Ideally the developer calling a Web service from an ASP.NET Web page should be able to work with the Web service using the same syntax as if she was working with a component local to the Web server.
Since calling a Web service involves marshalling the ingoing parameters properly and being able to marshal the return parameters properly, obviously performing such actions in an ASP.NET Web page would make the syntax differ wildly from using a local component, where such explicit marshalling was not needed.
In order to achieve the end goal of treating a Web service call just like a call to a local component, the .NET framework contains a command-line program called wsdl.exe ( W eb S ervice D escription L anguage), which creates a proxy class for a specific Web service.
This proxy class serves as an intermediate between the ASP.NET Web page and the Web service. ( The diagram on the next slide should help clarify this… )
The Role of the Proxy Class WEB SERVER #2 Web service WEB SERVER #1 SomePage.aspx an ASP.NET Web page PROXY CLASS STEP 3: The Web service unmarshals the incoming parameters, runs the method, and marshals the output parameters. These are sent back in an HTTP response. STEP 1: The ASP.NET Web page SomePage.aspx instantiates an instance of the Proxy class: Dim objClass = New ProxyClassName And calls one of the Web service methods: objClass . MethodName ( paramList ) STEP 2: The proxy class marshals the parameter list and makes an HTTP request to the Web service sitting on Web Server #2 STEP 4: The proxy class unmarshals the return parameters and passes back the result to the ASP.NET Web page. Transaction complete!
When creating a proxy class, you must specify the WSDL for the Web service. This XML-formatted file contains information on the incoming and outgoing parameters. See http://localhost/UCSDTeaching/Session6/SimpleWebService.asmx?WSDL
Create the proxy class by simply calling wsdl.exe with the full URL of the WSDL as the parameter:
Let’s take a moment and examine Math.cs , the source code for the Proxy class created by wsdl.exe
Note that the Proxy class is in C# - wsdl.exe provides a command-line switch to specify what language to use.
Note that a class is created with the same name as the Web service class ( Math , in this example). Also, for each public Web method there is a public method in the Proxy class with the correct input and output parameters.
Ideally, we’d like to be able to call Web services from an ASP.NET Web page in an identical fashion to which we call local components.
Creating a Proxy class allows us to call a Web service’s methods as if the Web service resided locally. The Proxy class handles the actual HTTP request as well as the marshalling of the input and output parameters.
The command-line program wsdl.exe can create the source code of the Proxy class for us based upon a Web service’s WSDL. Once this class is compiled and placed in the in directory, it can be used through an ASP.NET Web page.
Questions??? Now would be a great time to ask questions! Don’t you think? So ask away!