April 16, 2014
Hot Topics:
RSS RSS feed Download our iPhone app

WSDL Essentials, Page 2

  • February 25, 2003
  • By Developer.com Staff, Developer.com Staff
  • Send Email »
  • More Articles »

WSDL Invocation Tools, Part II

Our initial discussion of WSDL invocation tools focused on programming and command-line invocation tools. We now move on to even simpler tools that are entirely driven by a web-based interface.

The GLUE Console

In addition to supporting a number of command-line tools, the GLUE platform also supports a very intuitive web interface for deploying new services and connecting to existing services.

To start the GLUE console, just type:
console

This will automatically start the GLUE console on the default port 8100. Open a web browser and you will see the GLUE console home page. (See Figure 6-5.)

Figure 6-5. The GLUE console: index page

 

In the text box entitled WSDL, you can enter the URL for any WSDL file. For example, try entering the URL for the eBay Price Watcher Service, http://www.xmethods.net/sd/2001/EBayWatcherService.wsdl.

Click the WSDL button, and you will see the Web Service overview page. (See Figure 6-6.) This page includes a description of the specified service (extracted from the WSDL document element) and a list of public operations. In the case of the eBay service, you should see a single getCurrentPrice method.

Figure 6-6. The GLUE console: Web Service overview page for the eBay Price Watcher Service

 

Click the getCurrentPrice method, and you will see the Web Method overview page. (See Figure 6-7.) This page includes a text box where you can specify the input auction ID.

Figure 6-7. The GLUE console: Web Method overview page for the getCurrentPrice method

 

Enter an auction ID, click the Send button, and GLUE will automatically invoke the remote method and display the results at the bottom of the page. For example, Figure 6-8 shows the current bid price for the Handspring Visor Deluxe. Note that the price has already gone up $10 since invoking the service via the GLUE command-line tool!

Figure 6-8. The GLUE console: invoking the getCurrentPrice method (results of the invocation are displayed at the bottom of the screen)

 

SOAPClient.com

If you would like to try out a web-based interface similar to GLUE, but don't want to bother downloading the GLUE package, consider the Generic SOAP Client available at SOAPClient.com.

Figure 6-9 shows the opening screen to the Generic SOAP Client. Much like the GLUE console, you can specify the address for a WSDL file in this screen.

Figure 6-9. The Generic SOAP Client, available from SOAPClient.com

 

Specify the same eBay Price Watcher Service WSDL file, and the SOAP Client will display a text box for entering the auction ID. (See Figure 6-10.)

Figure 6-10. The Generic SOAP Client: Displaying information on the XMethods eBay Price Watcher Service

 

Figure 6-11 displays the result of the eBay service invocation. The Handspring Visor is up another $4!

Figure 6-11. The Generic SOAP Client: Response from the XMethods eBay Price Watcher Service

 

Automatically Generating WSDL Files

One of the best aspects of WSDL is that you rarely have to create WSDL files from scratch. A whole host of tools currently exists for transforming existing services into WSDL descriptions. You can then choose to use these WSDL files as is or manually tweak them with your favorite text editor. In the discussion that follows, we explore the WSDL generation tool provided by GLUE.

TIP:  If you create WSDL files from scratch or tweak WSDL files generated by a tool, it is a good idea to validate your final WSDL documents. You can download a WSDL validator from http://pocketsoap.com/wsdl/. This package requires that you have an XSLT engine and the zvonSchematron (http://www.zvon.org/), but installation only takes a few minutes. Once installed, the validator is well worth the effort and creates nicely formatted HTML reports indicating WSDL errors and warnings.

GLUE java2wsdl Tool

The GLUE platform includes a java2wsdl command-line tool for transforming Java services into WSDL descriptions. The command-line usage is as follows:

usage: java2wsdl <arguments>
 
where valid arguments are:
  classname                     name of java class
  -d directory                  output directory
  -e url                        endpoint of service
  -g                            include GET/POST binding
  -m map-file                   read mapping instructions
  -n namespace                  namespace for service
  -r description                description of service
  -s                            include SOAP binding
  -x command-file               command file to execute

Complete information on each argument is available online within the GLUE User Guide at http://www.themindelectric.com/products/glue/releases/GLUE-1.1/docs/guide/index.html. For now, we will focus on the most basic arguments.

For example, consider the PriceService class in Example 6-4. The service provides a single getPrice( ) method.

Example 6-4: PriceService.java

package com.ecerami.soap.examples;
 
import java.util.Hashtable;
/**
 * A Sample SOAP Service
 * Provides Current Price for requested Stockkeeping Unit (SKU)
 */
public class PriceService {
  protected Hashtable products;
 
  /**
   * Zero Argument Constructor
   * Load product database with two sample products
   */
  public PriceService (  ) {
    products = new Hashtable(  );
    //  Red Hat Linux
    products.put("A358185", new Double (54.99));
    //  McAfee PGP Personal Privacy
    products.put("A358565", new Double (19.99));
  }
 
  /**
  *  Provides Current Price for requested SKU
  *  In a real-setup, this method would connect to
  *  a price database.  If SKU is not found, method
  *  will throw a PriceException.
  */
  public double getPrice (String sku)
    throws ProductNotFoundException {
    Double price = (Double) products.get(sku);
    if (price == null) {
      throw new ProductNotFoundException ("SKU: "+sku+" not found");
    }
    return price.doubleValue(  );
  }
}

To generate a WSDL file for this class, run the following command:

java2wsdl com.ecerami.soap.examples.PriceService -s -e http://localhost:
 8080/soap/servlet/rpcrouter -n urn:examples:priceservice

The -s option directs GLUE to create a SOAP binding; the -e option specifies the address of our service; and the -n option specifies the namespace URN for the service. GLUE will generate a PriceService.wsdl file. (See Example 6-5.)

TIP:   If your service is defined via a Java interface and you include your source files within your CLASSPATH, GLUE will extract your Javadoc comments, and turn these into WSDL documentation elements.

Example 6-5: PriceService.wsdl (automatically generated by GLUE)

<?xml version='1.0' encoding='UTF-8'?>
<!--generated by GLUE-->
<definitions name='com.ecerami.soap.examples.PriceService'
   targetNamespace='http://www.themindelectric.com/wsdl/com.ecerami.soap.
       examples.PriceService/'
 
   xmlns:tns='http://www.themindelectric.com/wsdl/com.ecerami.soap.
       examples.PriceService/'
   xmlns:electric='http://www.themindelectric.com/'
   xmlns:soap='http://schemas.xmlsoap.org/wsdl/soap/'
   xmlns:http='http://schemas.xmlsoap.org/wsdl/http/'
   xmlns:mime='http://schemas.xmlsoap.org/wsdl/mime/'
   xmlns:xsd='http://www.w3.org/2001/XMLSchema'
   xmlns:soapenc='http://schemas.xmlsoap.org/soap/encoding/'
   xmlns:wsdl='http://schemas.xmlsoap.org/wsdl/'
   xmlns='http://schemas.xmlsoap.org/wsdl/'>
  <message name='getPrice0SoapIn'>
    <part name='sku' type='xsd:string'/>
  </message>
  <message name='getPrice0SoapOut'>
    <part name='Result' type='xsd:double'/>
  </message>
  <portType name='com.ecerami.soap.examples.PriceServiceSoap'>
    <operation name='getPrice' parameterOrder='sku'>
      <input name='getPrice0SoapIn' message='tns:getPrice0SoapIn'/>
      <output name='getPrice0SoapOut' message='tns:getPrice0SoapOut'/>
    </operation>
  </portType>
  <binding name='com.ecerami.soap.examples.PriceServiceSoap'
      type='tns:com.ecerami.soap.examples.PriceServiceSoap'>
    <soap:binding style='rpc' 
      transport='http://schemas.xmlsoap.org/soap/http'/>
    <operation name='getPrice'>
      <soap:operation soapAction='getPrice' style='rpc'/>
      <input name='getPrice0SoapIn'>
        <soap:body use='encoded'
         namespace='urn:examples:priceservice'
         encodingStyle='http://schemas.xmlsoap.org/soap/encoding/'/>
      </input>
      <output name='getPrice0SoapOut'>
        <soap:body use='encoded'
        namespace='urn:examples:priceservice'
        encodingStyle='http://schemas.xmlsoap.org/soap/encoding/'/>
      </output>
    </operation>
  </binding>
  <service name='com.ecerami.soap.examples.PriceService'>
    <port name='com.ecerami.soap.examples.PriceServiceSoap'
      binding='tns:com.ecerami.soap.examples.PriceServiceSoap'>
      <soap:address location='http://207.237.201.187:8080
          /soap/servlet/ rpcrouter'/>
    </port>
  </service>
</definitions>

You can then invoke the service via SOAP::Lite:

use SOAP::Lite;
 
print "Connecting to Price Service...\n";
print SOAP::Lite
   -> service('http://localhost:8080/wsdl/PriceService.wsdl')
   -> getPrice ('A358185');

Hopefully, this example illustrates the great promise of web service interoperability. We have a WSDL file generated by GLUE, a server running Java, and a client running Perl, and they all work seamlessly together.

Connecting to Price Service...
54.99

WARNING:   The IBM Web Services Toolkit (available at http://www.alphaworks.ibm.com/tech/webservicestoolkit) provides a WSDL generation tool called wsdlgen. This tool can take existing Java classes, Enterprise JavaBeans, and Microsoft COM objects and automatically generate corresponding WSDL files. However, as this book goes to press, the wsdlgen tool creates files based on the 1999 version of the W3C XML Schema. The WSDL files are therefore incompatible with other WSDL invocation tools, such as SOAP::Lite and GLUE. If you choose to use the IBM tool, make sure to manually update your WSDL files to reflect the latest version of XML Schema (http://www.w3.org/2001/XMLSchema).





Page 2 of 4



Comment and Contribute

 


(Maximum characters: 1200). You have characters left.

 

 


Sitemap | Contact Us

Rocket Fuel