Design Guidelines for XML Web Services Created Using ASP.NET
Web services is a powerful technology for providing services that can be accessed programmatically across the Internet. The following recommendations can help you create proficient Web services:
Web services support both synchronous and asynchronous communication between the client and the server that hosts the Web service. Under synchronous communication, the client sends a request for a service to the service host server and waits for the response. This prevents the client from performing other operations while waiting for the results. Asynchronous communication, however, causes the client to continue processing other tasks as it waits for a response. The client responds to the result of the service request when it becomes available.
When you use the Web Services Description Language tool (Wsdl.exe) to create your proxy class, it generates the standard, synchronous versions and asynchronous versions of the methods in the class. The asynchronous versions consist of two methods called Begin and End. The Begin method is used to initiate the Web service, while the End method retrieves the results.
Using asynchronous communication improves system usage and avoids delays on the client while it waits for the Web service results.
For a code example, see How to: Make an Asynchronous Call from a Web Service Client. For additional information on asynchronous communication, see Communicating with XML Web Services Asynchronously.
Making numerous service requests across the Internet can affect the performance of the client application. When designing your Web service, make efficient use of service requests by creating methods that group related information together. For example, suppose you have a Web service that retrieves information about a book. Instead of having separate methods to retrieve the book title, author, and publisher, create a method that returns all this information in one service request. It is more efficient to transfer a large block of information at one time than multiple smaller blocks of information.
For a code example, see How to: Group Related Information into a Single Web Service Method. When designing your Web service, be sure to use standard object-oriented programming practices. Use encapsulation to hide implementation details. For more complex Web services, you can use inheritance and polymorphism to reuse code and simplify your design.
For a code example, see How to: Use Inheritance in a Web Service. Use output caching to improve the performance of your Web service. When output caching is turned on, the results of a service request are stored in the output cache for a specified duration. If a similar Web service request is made, the result can be obtained from the cache, rather than recalculating it. This improves the reaction time of the Web service by reducing the processing required by the Web service server. Caching can be performed on both the client and the server. The Duration property allows you to specify the amount of time to cache the output of a Web service.
The directive to enable output caching on the client is:
<%@ OutputCache Duration="60" %> For a code example, see How to: Enable Output Caching on a Web Service Client.You can also use the CacheDuration property of the WebMethod attribute class to enable caching on the server. For a code example, see How to: Enable Server-Side Output Caching for a Web Service.
When designing your Web service, try to follow the structure of how a schema is formatted.
Web services use SOAP as the primary transport and serialization protocol. A SOAP message consists of an optional set of headers and the message body. The header section contains information that can be processed by the infrastructure on the Web server. SOAP does not define any headers. The body section contains information processed by an application, such as the parameters or return value for a Web service.
For additional information on using SOAP headers, see Using SOAP Headers.
Provide documentation for your Web service, such as a static HTML file, that describes the operation of your service and the data structures. Also include examples of how to use the Web service. Do not rely on the service description or the service help page as your only documentation.
TasksHow to: Make an Asynchronous Call from a Web Service Client
How to: Group Related Information into a Single Web Service Method
How to: Use Inheritance in a Web Service
How to: Enable Output Caching on a Web Service Client
How to: Enable Server-Side Output Caching for a Web Service
ConceptsCommunicating with XML Web Services Asynchronously
Other ResourcesXML Web Services Using ASP.NET
Using SOAP Headers