Asynchronous XML Web Service MethodsĀ
To improve performance of Web service methods that invoke long-running methods that block their thread, you should consider exposing them as asynchronous Web service methods. Implementing an asynchronous Web service method allows that thread to execute other code when it is returned to the thread pool. This allows one more of the limited number of threads in the thread pool to execute, enhancing the overall performance and scalability of the system.
For a step-by-step explanation of how to convert a Web service method into a pair of methods designed for asynchronous access, see How to: Create Asynchronous Web Service Methods. For an additional code example, see How to: Chain Asynchronous Calls with a Web Service Method.
In general, Web service methods that call methods that perform I/O operations are good candidates for asynchronous implementation. Examples of such methods include methods that communicate with other Web services, access remote databases, perform network I/O, and read and write to large files. All these methods spend the bulk of their time executing in hardware, which leaves the thread for executing the Web service method blocked. That thread can be freed up to execute other code if the Web service method is implemented asynchronously.
Regardless of whether a Web service method is implemented asynchronously, clients can communicate with it asynchronously. Asynchronous communication is exposed to .NET clients within the proxy class that is generated by the Web Services Description Language (WSDL.EXE) tool, even if a Web service method is implemented synchronously. The proxy class contains Begin and End methods for communicating with each Web service method asynchronously. Therefore, the decision to implement a Web service method asynchronously or synchronously should be based upon performance.
Note
The implementation of an asynchronous Web service method has no impact on the HTTP connection between the client and the server hosting the Web service. The HTTP connection is neither closed nor pooled.
See Also
Tasks
How to: Create Asynchronous Web Service Methods
How to: Chain Asynchronous Calls with a Web Service Method
Concepts
Communicating with XML Web Services Asynchronously