Tải bản đầy đủ (.pdf) (7 trang)

Viewing a WSDL File and Testing a Web Service

Bạn đang xem bản rút gọn của tài liệu. Xem và tải ngay bản đầy đủ của tài liệu tại đây (48.02 KB, 7 trang )


Viewing a WSDL File and Testing a Web Service
WSDL stands for Web Services Description Language, and a WSDL file contains a
complete description of your Web service, including the information required to call your
service's methods. A WSDL file is written in XML and specifies the following
information:

Web service 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 Web service 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 a Web service

Note You can also access your Web service 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 WSDL File for the Web Service
If you click the Service Description link, you'll see the description of your Web service in
the form of a WSDL file, which is shown in Listing 17.3


. Notice that this WSDL file is
written in XML and contains the details on 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 your methods.
Listing 17.3: WEB SERVICE WSDL FILE

<?xml version="1.0" encoding="utf-8"?>
<definitions
xmlns:http="
xmlns:soap="
xmlns:s="
xmlns:s0="http://DbProgramming/NorthwindWebService"
xmlns:soapenc="
xmlns:tm="
xmlns:mime="
targetNamespace="http://DbProgramming/NorthwindWebService"
xmlns="
<types>
<s:schema elementFormDefault="qualified"
targetNamespace="http://DbProgramming/NorthwindWebService">
<s:import namespace=" />
<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=" 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.

Testing a Web Service
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 Web service 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

×