You can also employ an asynchronous call for a method on a Web service along with a synchronous call. What's special about asynchronous programming? The unique thing in asynchronous programming is that after sending the request to the Web service, the client need not wait for the request to be completed. If a large amount of data is to be returned from a Web service, you can use the asynchronous method. This will greatly improve the application performance. The client can do any further useful execution until the result is returned from the Web service. It is imperative to note that a Web service does not have to be exclusively written to handle asynchronous requests to be called asynchronously. When the proxy class is created using either Wsdl.exe or Visual Studio .NET for synchronous call, the methods needed for calling the Web service method asynchronously are also created automatically. Two Asynchronous Methods (Begin and End)For each synchronous method, there is a Begin and an End asynchronous method. For example, in the proxy Concatenate.cs file, for the synchronous Concatenate( ) method, there are two asynchronous methods: BeginConcatenate( ) and EndConcatenate( ) , as shown next . [View full width]
The Begin method is called by a client to start the process of the Web service method (request). The End method is called by the client to get the results of the processing done by the Web service method call (response). After calling the Begin method to start the process, when do we have to call the End method? How will we know the asynchronous Web service call has completed? There are four ways to determine when the asynchronous Web service call has completed.
Let us discuss the first two methods in detail. |