Home > Articles > Web Services > XML

  • Print
  • + Share This
From the author of

WSDL Utilities

Working with tools from Apache AXIS, the steps in setting up a WSDL infrastructure for a web service are as follows:

  1. Define a Java interface for the service. The first step is to define a Java interface that describes the web service. For our ZwiftBooks web service (which we’ll call ZB), the input is ISBN and ZIP code; the output is price and estimated delivery time. To keep things simple, we’ve decided to have our SOAP service return the price and time quote as a single string of the following form:
    $79.99 / 2 days

    This means that our interface has one method that takes two parameters, ISBN and ZIP code, and looks like this:

    // Interface for a ZB price/time quote.
    public interface ZwiftBooksQuote {
     public String getPriceTimeQuote(String isbn, String zipcode);
  2. Generate the WSDL, using Java2WSDL. Once the interface has been compiled, use the Java2WSDL utility to generate the WSDL. With Java2WSDL in our CLASSPATH, it’s simply a matter of invoking Java2WSDL with the appropriate parameters. The following command line will generate the WSDL file we need. The complete command line looks like this:
    % java org.apache.axis.wsdl.Java2WSDL
     -o zwiftbooks.wsdl
     -l "http://www.zwiftbooks.com/ws/pricetime"
     -n "http://www.zwiftbooks.com"

    Here’s the breakdown:

    • -o indicates the name of the output WSDL file.
    • -l indicates the location of the service.
    • -n is the target namespace of the WSDL file.

    We want our WSDL output file to be called zwiftbooks.wsdl, so we use the -o parameter. The WSDL document generated comes complete with WSDL types, messages, portType, bindings, and service descriptions for communicating with our server using a SOAP RPC encoding. The WSDL file generated is shown in Listing 1, at the end of this procedure.

  3. Create SOAP bindings, using WSDL2Java. The Apache Axis toolkit assumes SOAP as the web services communications medium. Rather than code a SOAP client and server program by hand, we can simply use WSDL2Java to build Java client/server bindings based on the WSDL generated in step 2, or from WSDL you acquire from some server advertising its web service.

    The command-line execution of WSDL2Java will look something like this:

    % java org.apache.axis.wsdl.WSDL2Java -o .
      -d Session -s -S true zwiftbooks.wsdl

The WSDL2Java program creates two sets of Java classes. One set can be used by a client that wants to send a proper SOAP request to a web service but doesn’t want to worry about the details of SOAP messaging. The other set of classes created by WSDL2Java is intended for use by the web service provider, to accept SOAP messages that result in triggering the appropriate service call and converting the results back into a SOAP message for the client.

Listing 1 WSDL created by the Apache Axis Java2WSDL utility.

<?xml version="1.0" encoding="UTF-8"?>

<!--WSDL created by Apache Axis version: 1.2.1
Built on Jun 14, 2005 (09:15:57 EDT)-->

 <wsdl:message name="getPriceTimeQuoteRequest">
  <wsdl:part name="in0" type="soapenc:string"/>
  <wsdl:part name="in1" type="soapenc:string"/>

 <wsdl:message name="getPriceTimeQuoteResponse">
  <wsdl:part name="getPriceTimeQuoteReturn" type="soapenc:string"/>

 <wsdl:portType name="ZwiftBooksQuote">
  <wsdl:operation name="getPriceTimeQuote"
      parameterOrder="in0 in1">
   <wsdl:input message="impl:getPriceTimeQuoteRequest"

   <wsdl:output message="impl:getPriceTimeQuoteResponse"

 <wsdl:binding name="http://www.zwiftbooks.comSoapBinding"

  <wsdlsoap:binding style="rpc"

  <wsdl:operation name="getPriceTimeQuote">

   <wsdlsoap:operation soapAction=""/>
   <wsdl:input name="getPriceTimeQuoteRequest">

    namespace="http://www.zwiftbooks.com" use="encoded"/>

   <wsdl:output name="getPriceTimeQuoteResponse">
    namespace="http://www.zwiftbooks.com" use="encoded"/>



 <wsdl:service name="ZwiftBooksQuoteService">

  <wsdl:port binding="impl:http://www.zwiftbooks.comSoapBinding"

  <wsdlsoap:address location="http://www.zwiftbooks.com"/>



Figure 4 demonstrates the power of these WSDL utilities. With all these tools readily available, you have everything you need to support your web service with client- and server-side code and to deploy the web service!

Figure 4

Figure 4 Numerous tools exist that support generation of code to handle SOAP messages.

  • + Share This
  • 🔖 Save To Your Account