ASP+ Web Service proxies support both a synchronous and asynchronous execution model. Synchronous execution is conceptually much simpler to understand: it works just like a normal method call in a class. Asynchronous execution, however, can potentially provide much better system utilization and avoids blocking the calling worker thread while waiting for a network response.
Developers call asynchronous methods by splitting their code across two separate routines; one routine invokes and initiates the method (that would otherwise block), and another routine called when the async operation completes in order to obtain the result.
The below example demonstrates calling the previously defined GetStockDetails web service method using the async pattern.
DataSet msftDetails; Investor investorService = new Investor(); //call the Begin method, and send as null the AsyncCallback, and StateObject IAsyncResult result = investorService.BeginGetStockDetails(“MSFT”, null, null); result.AsyncWaitHandler.WaitOne(); msftDetails = investorService.EndGetStockDetails();
Asynchronous methods created for the client are different than the asynchronous support ASP+ Web Services offers. Client side async, as this example shows, is for the client consumer of the service to call the WebMethod. The method is then called on a thread with a single request and response. There is no callback from the server providing the service and the client.