ASP.NET

Conclusion: Web Services

Web services represent the next generation of computer connectivity. Instead of relying upon a closed network protocol and wire format, Web services open up the availability of an application to the entire world. Web services are built upon an already existing network using a wire format that many enterprises agree upon for making method calls.

ASP.NET automates the detailed work necessary to unpack a SOAP request and turn it into a real method call. ASMX files are handlers in the same way as ASPX and ASHX files. ASMX files implement IHttpHandler by parsing the incoming XML, calling a method in the code-behind class, and returning a result. Simply adorning the method with the [WebMethod] attribute inserts the necessary functionality.

Visual Studio is also useful for consuming Web services. By adding a Web reference to your application, Visual Studio will consult the Web service for the WSDL code and use it to build a proxy. From there you simply instantiate the proxy and call methods. The proxy takes care of preparing the SOAP payload and sending it. The proxies generated by Visual Studio also support asynchronous method invocation so that the main calling thread doesn't block for too long.

Tutorial 19 Quick Reference

How to create a Web service

  1. From an ASP.NET project, select Web Site | Add New Item from the main menu

  2. Select the Web Service template


Expose a class method as a Web method

Apply the [WebMethod] attribute immediately preceding the method signature


How to consume a Web service

  1. From within Visual Studio, select the project in solution explorer.

  2. Right-click on project

  3. Select Add Web Reference

  4. Surf to the Web service. Visual Studio will automatically ask for the WSDL and build a proxy