Creating Web Service Clients



Summary

With .NET, you can not only build Web services, but also create clients to access those Web services. With Visual Studio .NET, the tools for creating consumers and clients of Web services are easy to build and use. Just as the effective server-side tools have made exposing Web services a logical choice for many distributed applications, the tools and platforms that make it easy to consume them are also a very compelling reason to adopt this technology.

Here are some highlights and tips from this chapter:

  • The Web service help page includes in the HTML a link to a DISCO document.

  • This DISCO document links to the WSDL for the service.

  • This WSDL lists all of the information needed to build a proxy class that can be used to call this service.

  • Each client proxy class contains a method for calling the service synchronously, and two more methods for calling the operation asynchronously. Remember to use the asynchronous methods unless there is absolutely no reason to do so.

  • This proxy class also includes properties to control various aspects of the client behavior. Most important of these is the URL property used to set the location of the service endpoint.

It's also important to remember these potential snags:

  • The Add Web Reference dialog box in Visual Studio .NET acts like disco.exe—it downloads the DISCO, then downloads the WSDL, and then creates the proxy class from the WSDL. This code path is much like calling disco.exe and then wsdl.exe, but not exactly.

  • Updating a Web reference in Visual Studio .NET (or manually with wsdl.exe) will overwrite any changes you make to the proxy class.

  • Exceptions thrown on the service side will always be thrown on the proxy class as a SoapException.

  • Types on the server are not the same types as on the client. Web services are about interoperability, not type fidelity.