| |
Designing a WSDL Client, Discovering Web Services
You've built your UDDI client, now find out how to use it. This article explains how to build a WSDL client. Your client will download WSDL files, parse them to read interface details, author service invocation requests, and collect information on any Web service you investigate.
by Bilal Siddiqui
|
n the world of Web services, a business describes its services (activities or functionality) by using an XML-based structure called WSDL (Web Service Description Language).
When a service consumer wants to interact with a Web service, they merely download that service's WSDL file. The file tells what the service offers and how to interact with it.
In this article, I'll design a reusable WSDL Java client that can download any WSDL, parse it to read interface details, author service invocation requests, and collect information coming back from the WSDL service. I'll also explain WSDL's syntax, grammar, namespace rules, etc.
The interaction between the WSDL client and host service has four parts:
| |
 |
Figure 1. Here's the four step procedure for a WSDL-based Web service.
|
- Downloading the WSDL file. Start with a WSDL file URL. In some cases, you will know the location of the file you want, but you can also get the URL from a UDDI registry (please see the article "Constructing a UDDI Client, Calling the UDDI Registry"). An HTTP request is passed to the target URL, which returns a WSDL file. To download the WSDL file, use the HTTPConnection class shown in Listing 1.
- Processing the WSDLfile. Remember, the WDSL file is in XML, so you need an XML parser to process it. As in the UDDI article, you'll be using Enhydra's kXML. kXML's smaller footprint allows the WSDL client to work inside an applet as well as Java Foundation Classes/Swing containers. The WSDLClient class (Listing 2) processes the WSDL file.
- Authoring the service invocation request. Based on the information gathered in Step 2, the WSDL client formulates an XML request. Simple Object Access Protocol (SOAP) is the most popular transport facility available for sending Web service invocation requests. WSDL only tells the details of services, but once they are known, SOAP transports the requests as XML messages. The WSDL client uses the same SOAP-related classes that developed for the UDDI client in the previous article (SoapTransport.class in Listing 3, SoapCall.class in Listing 4, and HttpConnection.class in Listing 1).
- Processing the SOAP response: A class named SoapTransport extracts the response string from the SOAP envelope.
Figure 1 shows the sequence of these four events broken down into sub-steps. Step 4 is purely a SOAP issue and is outside the scope of this article. For more on using SOAP, please refer to the Resources box.
| |
 |
Figure 2. The arrangement of classes within the WSDL client.
|
Figure 2 shows the arrangement of classes within the WSDL client.
The WSDLAppletClient class (Listing 5) is a generic applet that provides a simple GUI as shown in Figure 3. The container must interact with three of our classes:
- The WSDLClient downloads a WSDL file from the specified URL, downloads it, parses it, and populates its internal data structures.
- The Operation class (Listing 6) creates the SOAP requests based on the operations described in the WSDL file. WSDL-based Web services consist of Operations. Think of a Web service as a Java or C++ class and Operations as its public methods. The WSDL parsing task is nothing but creating Operation objects.
- The Parameter class (Listing 7) builds and retrieves individual parameters (values) from the SOAP messages passed between the WSDL client and the Web service for each operation. Information about what parameters are required for a particular operation comes from the WSDL file. While parsing the WSDL file to create Operation objects, you also create the necessary Parameter objects for each operation.
| |
 |
Figure 3. This is an applet-based GUI to test the WSDL client.
|
Downloading the WSDL File
The HTTPConnection class makes an HTTP request to the URL, where the WSDL file is located. The WSDLClient class is the main processing client; it downloads the WSDL file, processes it, and populates the operation and message class objects. The GetOperations() method of the WSDLClient class returns a Vector of operation-type objects, allowing the container application to invoke an individual operation.
|