I ve built a simple webservice just for testing and whenever I implement it on my windows phone 8 solution(I add a refference) my methods which are decorated with the [webmethod] naturally seem to convert from type string for example to type void and at the end of the method name I see a async word. Can anyone please give me a suggestion how to fix that?
I need this webservice to target my database. I have to communicate with it via this webservice(actually using it as a proxy to get the the databaseserver). I doing everything locally. For example my webservice address is:
http://localhost:47852/Number.asmx?WSDL

Recommended Answers

All 3 Replies

Any particular reason you can't use the async keyword? If so, just take it off.

An async method returns a Task, the result of the Task is your data type. So it might say Task<string> which means you can call the webservice from your application (synchronously) by called webService.GetMyString().Result;

If you decide you can use async, you could simply call string myString = webService.GetMyString(); and the call will happen asynchronously until the result is required.

e.g.

public async Task CallServiceAndGetString()
{
    string myString = webService.GetMyString(); // Web Service call gets sent. Does not block, but lets say that this calls lasts 30 seconds for whatever reason.

    someClass.CallStarted = true; // WebService call still going
    someOtherClass.DoWork(); // Still going...

    MessageBox.Show(myString); // Blocks here until the original call completes
}

Tnx for the reply Ketsuekiame but in WP8 Framework a concatenation is generated everytime i create a method. I managed to sort that out by doing this:

  private void Button_Click_1(object sender, RoutedEventArgs e)
        {
            ServiceReference1.WebServiceSoapClient client = new ServiceReference1.WebServiceSoapClient();
            client.HelloWorldCompleted += new EventHandler<ServiceReference1.HelloWorldCompletedEventArgs>(target);
            client.HelloWorldAsync(); //Last word concatenated Async!
        }

        private void target(object sender, ServiceReference1.HelloWorldCompletedEventArgs e)
        {
            TextBox1.Text = e.Result;
        }

After two days i finally managed to communicate with my webservice which is located on the folowing DNS:www.somee.com.
I made a reference in the WP8 solution but somehow i couldn't get the communication. I wasn't aware that I have to deploy the webservice on the server(-.-), so I basically converted the solutionfolder to a Application. That action made the communication possible.
The reason why I needed this webservice was to target my database as mentioned on the question. I successfully managed to insert some data into the database querying it with the WP8 emulator BUT am now failing at getting the data from the database.
Bassically I have my .asmx file where I stored all my methods which I then call by providing the code(almost as same as above) to display the results in my WP8 emulator(listbox,textbox,picturebox...).
Am I doing this right? and is this the way this should be done or should I use another approach?

Oh you mean the old style Async! Sorry, I thought you meant the new one :)

That looks okay. I'd do it slightly differently by abstracting the client away, but your way isn't "wrong".
To answer your previous question about the async methods, you should be able to untick some box when you're generating the client code that says "Generate Async Methods" or something similar.

I'm not overly familiar with WP8, however if I recall correctly, you still need to update controls on the UI thread and the ASYNC return event may not be.
As such you'd want to do something similar to the following in order to update the control:

Deployment.Current.Dispatcher.BeginInvoke(()=> TextBox1.Text = e.Result);
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.