Code Model for Accessing Web Services in Managed Code
A Web service client is any component, service, or application that references and utilizes a Web service. It is worthwhile to note that Web service clients need not be a client-based application, such as a desktop application; in most cases, your Web service clients may be other Web applications or even other Web services.
When accessing Web services in managed code, a proxy class and the .NET Framework handle all of the infrastructure coding. Accessing a Web service follows these basic steps:
Locate the Web service you want to access.
Create a proxy class for the Web service by adding a Web reference to your project.
Reference the proxy class in the client code by including its namespace.
Create an instance of the Web service proxy class in the client code.
Access the Web service using the methods of the proxy.
For more information, see How to: Access a Web Service in Managed Code or How to: Access a Web Service Asynchronously in Managed Code.
To simplify the coding model, applications written in managed code use a Web reference to locally represent each Web service. You add a Web reference to your project using the Add Web Reference dialog box. This dialog box supports browsing Web addresses for a Web service. For more information, see Locating Web Services and Web References.
To access a Web service method, your client application invokes either the corresponding synchronous method or asynchronous methods of the proxy object. These methods in turn do the necessary work to remote the call over the wire to call the desired Web service method. By default, the proxy class uses SOAP to access the Web service method, as SOAP supports the richest set of data types of the three supported protocols (HTTP-GET, HTTP-POST, and HTTP-SOAP). For more information, see Web Service Wire Formats.
Using a proxy class that Visual Studio generated directly from the service description of a Web service, accessing a Web service in managed code is a relatively simple process. The proxy class does the work to transform the method call into a request message and the response message back into a method return value.
The following picture shows the relationship of an application that calls a Web service, which in turn calls another Web service to obtain pricing information. In this example, the Get Current Prices Web service is both a Web service provider and a Web service consumer.