views:

994

answers:

2

Hello, I am trying to make async web service call from asp.net 2.0 web client to WCF web service. I created the proxy class using the svcutil.exe with the async option. Here is an example of the client code calling the web service:

protected void Page_Load(object sender, EventArgs e)   
{   
  WSClient client = new WSClient();   
  AsyncCallback asyncCallback = new AsyncCallback(WebServiceCallback);   
  AsyncCallState asyncCallState = new AsyncCallState(client);   
  client.BeginWS(value, asyncCallback, asyncCallState);   
  Response.Write("Big Test");   
}  

public void WebServiceCallback(IAsyncResult ar)   
{   
  AsyncCallState asyncCallState = (AsyncCallState)ar.AsyncState;   
  WSsClient client = (WSClient)asyncCallState.WebServiceState;   

  WSClientResult result = client.EndWS(ar);   
}

Using the code for reference; everything in the Page_Load will execute but the page will not display the “Big Test” until the client.EndWS is executed in the callback. Which does not appear to be asynchronous. Any ideas or suggestions of how to make the asynchronous call asynchronous are appreciated.

+1  A: 

This is not a web service problem. You need to learn how ASP.NET works.

In particular, see Wicked Code: Asynchronous Pages in ASP.NET 2.0.

John Saunders
A: 

You need to add the async directive to the page! Once you have done this you can use completed and async.

e.g

Next you wire up event to somemethodcompleted({some eventhandler}) which you should find in your generated proxy.

Then call the somemethodasync. Will kick off the task.

Using this method will automatically enlist into the page tasks for the asp.net which will prevent you page lifecycle completing before the method has returned.

Hope that helps

RubbleFord