Xem một tập tin WSDL và thử nghiệm một dịch vụ web WSDL là viết tắt của Web Ngôn ngữ mô tả dịch vụ, và một tập tin WSDL chứa một mô tả đầy đủ các dịch vụ Web của bạn, bao gồm các thông tin cần thiết để gọi các phương pháp của dịch vụ. Một tập tin WSDL được viết bằng XML và quy định cụ thể các thông tin sau
Nội dung Text: Viewing a WSDL File and Testing a Web Service
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
• 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:
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
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:
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
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:
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
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 Web service in a Windows application.