ViewingaWSDLFileandTestingaWebServiceWSDL stands for Web Services Description Language, andaWSDLfile contains a complete description of your Web service, including the information required to call your service's methods. AWSDLfile is written in XML and specifies the following information: • Webservice methods • Data types used by the methods • Request and response message formats for communication with the methods Note For comprehensive information on WSDL, visit www.w3.org/TR/wsdl. You access your Webservice by pointing your browser to the following URL: http://localhost/NorthwindWebService/Customers.asmx As you can see from Figure 17.3 , the resulting page displayed in your browser contains two links named Service Description and Retrieve Customers. Figure 17.3: Accessing aWebservice Note You can also access your Webservice by right-clicking on the Customers.asmx file in the Solution Explorer window in VS .NET and selecting Set As Start Page from the pop-up menu. You then select Debug ➣ Start Without Debugging to test your service. VS .NET will start Internet Explorer and display the same test page as was shown in Figure 17.3 . Viewing the WSDLFile for the WebService If you click the Service Description link, you'll see the description of your Webservice in the form of aWSDL file, which is shown in Listing 17.3 . Notice that this WSDLfile is written in XML and contains the details on how to call the methods exposed by the example Web service. The WSDLfile also contains the data types of the parameters used and the calls you can make to your methods. Listing 17.3: WEBSERVICEWSDLFILE <?xml version="1.0" encoding="utf-8"?> <definitions xmlns:http="http://schemas.xmlsoap.org/wsdl/http/" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:s="http://www.w3.org/2001/XMLSchema" xmlns:s0="http://DbProgramming/NorthwindWebService" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:tm="http://microsoft.com/wsdl/mime/textMatching/" xmlns:mime="http://schemas.xmlsoap.org/wsdl/mime/" targetNamespace="http://DbProgramming/NorthwindWebService" xmlns="http://schemas.xmlsoap.org/wsdl/"> <types> <s:schema elementFormDefault="qualified" targetNamespace="http://DbProgramming/NorthwindWebService"> <s:import namespace="http://www.w3.org/2001/XMLSchema" /> <s:element name="RetrieveCustomers"> <s:complexType> <s:sequence> <s:element minOccurs="0" maxOccurs="1" name="whereClause" type="s:string" /> </s:sequence> </s:complexType> </s:element> <s:element name="RetrieveCustomersResponse"> <s:complexType> <s:sequence> <s:element minOccurs="0" maxOccurs="1" name="RetrieveCustomersResult"> <s:complexType> <s:sequence> <s:element ref="s:schema" /> <s:any /> </s:sequence> </s:complexType> </s:element> </s:sequence> </s:complexType> </s:element> <s:element name="DataSet" nillable="true"> <s:complexType> <s:sequence> <s:element ref="s:schema" /> <s:any /> </s:sequence> </s:complexType> </s:element> </s:schema> </types> <message name="RetrieveCustomersSoapIn"> <part name="parameters" element="s0:RetrieveCustomers" /> </message> <message name="RetrieveCustomersSoapOut"> <part name="parameters" element="s0:RetrieveCustomersResponse" /> </message> <message name="RetrieveCustomersHttpGetIn"> <part name="whereClause" type="s:string" /> </message> <message name="RetrieveCustomersHttpGetOut"> <part name="Body" element="s0:DataSet" /> </message> <message name="RetrieveCustomersHttpPostIn"> <part name="whereClause" type="s:string" /> </message> <message name="RetrieveCustomersHttpPostOut"> <part name="Body" element="s0:DataSet" /> </message> <portType name="CustomersSoap"> <operation name="RetrieveCustomers"> <input message="s0:RetrieveCustomersSoapIn" /> <output message="s0:RetrieveCustomersSoapOut" /> </operation> </portType> <portType name="CustomersHttpGet"> <operation name="RetrieveCustomers"> <input message="s0:RetrieveCustomersHttpGetIn" /> <output message="s0:RetrieveCustomersHttpGetOut" /> </operation> </portType> <portType name="CustomersHttpPost"> <operation name="RetrieveCustomers"> <input message="s0:RetrieveCustomersHttpPostIn" /> <output message="s0:RetrieveCustomersHttpPostOut" /> </operation> </portType> <binding name="CustomersSoap" type="s0:CustomersSoap"> <soap:binding transport="http://schemas.xmlsoap.org/soap/http" style="document" /> <operation name="RetrieveCustomers"> <soap:operation soapAction="http://DbProgramming/NorthwindWebService/RetrieveCustomers" style="document" /> <input> <soap:body use="literal" /> </input> <output> <soap:body use="literal" /> </output> </operation> </binding> <binding name="CustomersHttpGet" type="s0:CustomersHttpGet"> <http:binding verb="GET" /> <operation name="RetrieveCustomers"> <http:operation location="/RetrieveCustomers" /> <input> <http:urlEncoded /> </input> <output> <mime:mimeXml part="Body" /> </output> </operation> </binding> <binding name="CustomersHttpPost" type="s0:CustomersHttpPost"> <http:binding verb="POST" /> <operation name="RetrieveCustomers"> <http:operation location="/RetrieveCustomers" /> <input> <mime:content type="application/x-www-form-urlencoded" /> </input> <output> <mime:mimeXml part="Body" /> </output> </operation> </binding> <service name="Customers"> <port name="CustomersSoap" binding="s0:CustomersSoap"> <soap:address location="http://localhost/NorthwindWebService/Customers.asmx" /> </port> <port name="CustomersHttpGet" binding="s0:CustomersHttpGet"> <http:address location="http://localhost/NorthwindWebService/Customers.asmx" /> </port> <port name="CustomersHttpPost" binding="s0:CustomersHttpPost"> <http:address location="http://localhost/NorthwindWebService/Customers.asmx" /> </port> </service> </definitions> Next, you'll see how to test your Web service. TestingaWebService To test your Web service, point your browser to the following URL: http://localhost/NorthwindWebService/Customers.asmx Click the Retrieve Customers link. Your browser displays a page (see Figure 17.4 ) that you can use to test the RetrieveCustomers() method exposed by your Web service. Figure 17.4: The Webservice test page The test page contains a text box with a label of whereClause where you can enter values for the whereClause parameter of your RetrieveCustomers() method. The text you enter for your whereClause is passed to the RetrieveCustomers() method when you click the Invoke button on the page. Enter the following text as your whereClause: CustomerID='ALFKI' Click the Invoke button to run the RetrieveCustomers() method. With this whereClause, the RetrieveCustomers() method returns a DataSet with a DataTable containing the one row from the Customers table with a CustomerID of ALFKI, as shown in Figure 17.5 . Notice that the equals (=) and single quote (') characters in the whereClause parameter value of the URL have been converted to the codes %3D and %27 respectively. Figure 17.5: Running the RetrieveCustomers() method with a whereClause of CustomerID= 'ALFKI' As you can see from Figure 17.5 , the DataSet is returned as an XML document. You can use this XML in your client programs that use the Web service. You'll see how to write a client program in the next section . Let's take a look at another example; enter the following string as your whereClause and click the Invoke button: CustomerID IS NOT NULL This causes the RetrieveCustomers() method to return a DataSet with a DataTable containing all the rows from the Customers table (see Figure 17.6 ). Notice that the space characters in the whereClause parameter value have been converted to plus (+) characters. You'll need to scroll down the page to see the other customers. Figure 17.6: Running the RetrieveCustomers() method with a whereClause of CustomerID IS NOT NULL Next, you'll see how to use your Webservice in a Windows application. . Viewing a WSDL File and Testing a Web Service WSDL stands for Web Services Description Language, and a WSDL file contains a complete description. how to call the methods exposed by the example Web service. The WSDL file also contains the data types of the parameters used and the calls you can make to