This documentation is archived and is not being maintained.

Code Model for Accessing XML Web Services in Managed Code

An XML Web service client is any component, service, or application that references and utilizes an XML Web service. It is worthwhile to note that XML Web service clients need not be a client-based application, such as a desktop application; in most cases, your XML Web service clients may be other Web applications or even other XML Web services.

When accessing XML Web services in managed code, a proxy class and the .NET Framework handle all of the infrastructure coding. Accessing an XML Web service follows these basic steps:

  • Locate the XML Web service you want to access.
  • Create a proxy class for the XML 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 XML Web service proxy class in the client code.
  • Access the XML Web service using the methods of the proxy.

For more information, see Accessing an XML Web Service in Managed Code or Accessing an XML Web Service Asynchronously in Managed Code.

Locating an XML Web Service and Adding a Web Reference

To simplify the coding model, applications written in managed code use a Web reference to locally represent each XML 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 an XML Web service. For more information, see Locating XML Web Services and Web References.

Reference the Proxy Class

The generated proxy class has its own namespace associated with it, and you must add the namespace to your client application before you can create an instance of that class. For more information, see using Directive (C#) or References and the Imports Statement (Visual Basic .NET).

Create an Instance of the Proxy Class

Before you can call any of the methods of the proxy class, you must first create an instance of that class. This process does not differ at all from creating an instance of any other class. For more information, see new (C#) or Object Variable Declaration (Visual Basic .NET).

Access the XML Web Service Using the Proxy

To access an XML 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 XML Web service method. By default, the proxy class uses SOAP to access the XML 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 XML Web Service Wire Formats.

Summary

Using a proxy class that Visual Studio generated directly from the service description of an XML Web service, accessing an XML 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 an XML Web service, which in turn calls another XML Web service to obtain pricing information. In this example, the Get Current Prices XML Web service is both an XML Web service provider and an XML Web service consumer.

XML Web Service Clients and XML Web Services

991bcaxf.vbwebserviceclients(en-us,VS.71).gif

See Also

Accessing XML Web Services in Managed Code | Building XML Web Service Clients

Show: