The WebServiceUtil.exe utility takes the path to an SDL contract file and a language (CSharp, VB, or JavaScript) as input arguments. The utility then generates a single source file as output. This file contains a proxy class, defined using the language specified, that exposes methods (both synchronous and asynchronous) for each of the methods exposed by the web service. Each proxy method contains the appropriate network invocation and marshalling code necessary to invoke and receive a response from the remote service.
For example, consider the following SDL file:
<serviceDescription xmlns:s0="http://tempuri.org/main.xsd" xmlns:s1="" name="Investor" targetNamespace="" xmlns="urn:schemas-xmlsoap-org:sdl.2000-01-25"> <soap xmlns="urn:schemas-xmlsoap-org:soap-sdl-2000-01-25"> <service> <addresses> <address uri="http://localhost/test/Test.asmx"/> </addresses> <requestResponse name="GetStockDetails" soapMessageName="http://tempuri.org/GetStockDetails"> <request ref="s0:GetStockDetails"/> <response ref="s0:GetStockDetailsResult"/> </requestResponse> </service> </soap> <schema targetNamespace="http://tempuri.org/main.xsd" xmlns="http://www.w3.org/1999/XMLSchema"> <element name="GetStockDetails"> <complexType> <element name="symbol" type="string"/> </complexType> </element> <element name="GetStockDetailsResult"> <complexType> <element name="result"> <complexType> <element ref="schema"/> <any/> </complexType> </element> </complexType> </element> </schema> <schema targetNamespace="" xmlns="http://www.w3.org/1999/XMLSchema"> <element name="DataSet"> <complexType> <element ref="schema"/> <any/> </complexType> </element> </schema> </serviceDescription>
The WebServiceUtil.exe utility uses the SDL to generate the following C# proxy class. Note that if multiple protocols are specified in the SDL file, the WebServiceUtil.exe utility will default to using SOAP within the proxy since it currently has the richest marshalling support:
namespace WebProxiesNamespace { using System.Xml.Serialization; using System.Web.Services.Protocols; using System.Web.Services; public class Investor : System.Web.Services.Protocols.SoapClientProtocol { public Investor() { this.Path = "http://localhost/test/Test.asmx"; } [System.Web.Services.Protocols.SoapMethodAttribute("http://tempuri.org/GetStockDetails")] public System.Data.DataSet GetStockDetails(string symbol) { object[] results = this.Invoke("GetStockDetails", new object[] {symbol}); return (System.Data.DataSet)(results[0]); } public System.IAsyncResult BeginGetStockDetails(string symbol, AsyncCallback callback, object asyncState) { return this.BeginInvoke("GetStockDetails", new object[] {symbol}, callback, asyncState); } public System.Data.DataSet EndGetStockDetails(System.IAsyncResult asyncResult) { object[] results = this.EndInvoke(asyncResult); return (System.Data.DataSet)(results[0]); } } }
Once an appropriate SDL Proxy has been generated for a service, a developer can invoke and access the returned result just like they would any other class or business component. For example:
DataSet msftDetails; DataSet ontcDetails; Investor investorService = new Investor(); msftDetails = investorService.GetStockDetails(“MSFT”); ontcDetails = investorService.GetStockDetails(“ONTC”);
Note that the proxy automatically manages the network IO, and appropriately marshals arguments to and from NGWS runtime types as needed. Errors from the web service are surfaced to the calling consumer using standard NGWS runtime exceptions. The namespace created is WebProxiesNamespace. The WebServiceUtil.exe program takes an argument for the name of this namespace. This file can also be edited and the namespace changed. Other classes can be created that inherit from it.