Skip to main content

Calling Webmethods Asyncronously

If you are using any web reference in your Windows Forms application or Web Site there might have been numerous occasions when you make a call to any of the web methods exposed by the web service.
Time taken by the web method to return is dependent on the network traffic and the method implementation.
We cannot block the main thread to wait for the web method to return.
This eats up the application responsiveness. It is advised to call the web methods asynchronously.
For every web method in ASP.NET 2.0 Web Service there is a corresponding Asynchronous method.

Web Service

For the Webmethod Helloworld() we have an Async method HelloWorldAsycn().
An Event HelloWorldCompleted and Event argument
Before making call to the async webmethod we need to attach a eventhandler corresponding to the completion of the method. In our case it is HelloWorldCompletedEventHandler.
This is how the client application will make the call, and the service will callback the event handler once the method execution is completed