Testing the XML Web Service

ASP.NET provides a simple way to test an XML Web service after you have deployed it to a virtual directory. If you request the .asmx file in a Web browser, you'll see an automatically generated test page that lists the available methods and the text descriptions you've added (as shown in Figure 5-3).

Figure 5-3. The CustomerDB test page

graphics/f05dp03.jpg

To test a Web method, you click one of the methods. A separate window will appear, with text boxes provided for parameters and with an Invoke button. When you click Invoke, the request message is sent, the XML Web service class is created, the Web method executes, the XML Web service class is destroyed, and the result is returned as an XML document that appears in the browser. Figure 5-4 shows the result of invoking the GetCustomers method from the test page. It returns an XML structure representing an array with five customers (two of which are collapsed in the screen shot).

Figure 5-4. The result of invoking GetCustomers

graphics/f05dp04.jpg

It's important to understand that this technique does not require any special functionality from your Internet browser it's simply a convenience provided by ASP.NET. If you were to type the exact same request string into a Netscape or Opera browser, you would receive the same test page and the same XML document. The request string is actually a request to the XML Web service using HTTP GET. It identifies the XML Web service, Web method, and any required parameters:

 http://[Server]/[VirtualDirectory]/[AsmxFile]/[WebMethod]?[Arguments] 

Here's the HTTP GET request required to get the list of all customers:

 http://localhost/CustomerDB/CustomerDB.asmx/GetCustomers? 

And here's another HTTP GET request string; this one retrieves information for the single customer record with the CustomerID of 1:

 http://localhost/CustomerDB/CustomerDB.asmx/GetCustomer?customerID=1 

Note that when you use the test page, the method of communication is HTTP GET (not SOAP). This means that you won't be able to test some methods in your browser, such as UpdateCustomer.

The WSDL Document

You also can request the WSDL document for your XML Web service by requesting the .asmx file with ?WSDL appended to the end of the request string. (The test page links directly to this document; just click Service Description.) The WSDL document has the same role the IDL file does in COM programming, except it uses an XML-based syntax rather than a C-based syntax.

The WSDL document is far from compact. It's designed to be independent of communication protocols (like HTTP) and encoding methods (like SOAP), which gives it the ability to be used with future technologies. Unfortunately, this also means that the WSDL document requires a lengthy, multipart structure. If you browse through the WSDL document for the CustomerDB XML Web service, you'll find information about the supported methods and the custom-defined CustomerDetails class (excerpted here):

 <s:complexType name="CustomerDetails">   <s:sequence>     <s:element minOccurs="1" maxOccurs="1" name="ID" type="s:int" />      <s:element minOccurs="0" maxOccurs="1" name="Name"                 type="s:string" />      <s:element minOccurs="0" maxOccurs="1" name="Email"                 type="s:string" />      <s:element minOccurs="0" maxOccurs="1" name="Password"                type="s:string" />    </s:sequence> </s:complexType> 

Fortunately, there is little need to read the WSDL document directly. If you're creating a .NET client, you can create a proxy class based on the WSDL document automatically. The same feat is possible with many third-party tools in non-.NET languages.



Microsoft. NET Distributed Applications(c) Integrating XML Web Services and. NET Remoting
MicrosoftВ® .NET Distributed Applications: Integrating XML Web Services and .NET Remoting (Pro-Developer)
ISBN: 0735619336
EAN: 2147483647
Year: 2005
Pages: 174

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net