Welcome!

.NET Authors: Bruce Armstrong, Marek Miesiac, Jason Dolinger, Yeshim Deniz, Liz McMillan

Related Topics: SOA & WOA

SOA & WOA: Article

Interoperable SOAP

Interoperable SOAP

The purpose of SOAP is to enable transparent - language- and platform-independent - access to services. Until recently, getting Microsoft- and Java-based SOAP applications to work together has been difficult.

Using the newest SOAP implementations, this article demonstrates how to use SOAP's RPC messaging between Microsoft ASPs and Java JSPs and servlets.

As the World Wide Web Consortium (W3C) works to stabilize its recommendation for SOAP and SOAP-related technologies, transparent access to services continues to be problematic. Creating a SOAP application for a single platform, like just Microsoft or just Java, usually works well. However, getting it to work across platforms, like across Microsoft and Java, can be challenging. Often, to avoid cross-platform interoperabilities, developers choose to write low-level code that creates and parses the XML in SOAP messages.

Another solution that allows developers to concentrate on using services is to use SOAP's RPC-oriented messages. RPC-oriented messages are much like traditional function or method calls, where the sender passes data into a method using arguments, and receives data back in return. RPC-oriented messages are well suited for COM or Java objects communicating via SOAP. This article demonstrates how to create RPC-based, interoperable SOAP applications using the latest SOAP implementations from Microsoft (SOAP Toolkit 2.0 SP2) and for Java (Apache's Axis beta 3). It examines using a Java application as a SOAP client with a Microsoft SOAP server and vice versa.

Interoperability Problems
Two primary complications make it difficult to create interoperable Microsoft- and Java-based SOAP applications. The use (or non-use in the case of some Java-based implementations) of a Web Services Description Language (WSDL) file is one complication. The other is related to the structure of SOAP messages. When using RPC-oriented messages, the SOAP middleware represents an operation's input and return data as XML so that neither the client nor the server has to work directly with XML. Sometimes the messages used by Microsoft and Java SOAP middleware are incompatible with each other.

WSDL and SOAP
A WSDL file describes (in XML format) the services (or set of operations) offered by a server.. Microsoft SOAP relies on WSDL. In contrast, many Java implementations do not require it, and some may not even support it.

A WSDL file typically has five sections: types, message, portType, binding, and service (see Figure 1). A portType section lists the operations available to the client. There is one named getCondition. The message section maps at most one input and one output message to an operation. In Figure 1, the messages Weather.getCondition and Weather.getConditionResponse are the input and output, respectively, for operation getCondition. These message definitions specify the SOAP message structure, including the name and data types of the arguments. Notice that the Weather.getCon- dition message has one string argument named where. A service section defines how a SOAP client should handle ports, or groups of operations. The port usually specifies the URL of a SOAP request handler, like http://soapServer/soapService.asp in this example. The remaining two sections, binding and types, are less important for interoperability issues, and Figure 1 does not show their details.

 

Since many SOAP implementations provide tools to automatically generate a WSDL file from a COM object or Java class files, a developer may seldom have to completely write it. However, a developer of SOAP client code may have to know the relationship between a WSDL service, port, and operation. It is possible for a single WSDL file to define multiple services. Furthermore, each service may define many ports. Lastly, each port lists a group of operations handled by a SOAP server.

The problem with WSDL and SOAP is that implementers, particularly in the Java camp, have realized that WSDL is not a necessary part of SOAP. In addition, the W3C has not included the WSDL specification in their working draft of SOAP 1.2, and has not embraced using WSDL as a standard way of describing Web services. Since Microsoft's SOAP implementation is dependent on WSDL (in fact, even Microsoft's SOAP server, alone, needs it), using it with an implementation of SOAP that does not use WSDL is problematic. So for interoperable solutions, the Java SOAP server should supply a WSDL file.

SOAP Messages
SOAP messages vary depending on whether a SOAP implementation uses a WSDL file. The WSDL file specifies the structure of SOAP request and response messages. For SOAP implementations that do not require the WSDL, the structure of the messages is implied, or is manipulated through code.

While Java implementations may vary, the approach used by Axis is representative. A SOAP client calls the operation getCondition, which takes a string argument, a city, and returns the current weather condition.

The Microsoft request message has the name of the operation in both the HTTP header (the value of SOAPAction) and in the Body element of the SOAP envelope. Also, the argument for getCondition is labeled where. WSDL specifies the value of SOAPAction (in the binding section) and the labels for the arguments (in the message section). If the request message does not have a SOAPAction and correct argument labels, Microsoft's SOAP handler on the server will fail.

In the default (implied) request message from Axis, SOAPAction in the HTTP header does not have a value, and the argument for getCondition is labeled arg0, instead of where. The Axis SOAP handler on the server only looks for the name of the operation in the SOAP envelope (not the HTTP header), and it doesn't care what the arguments of the operation are named, just their presence and order. A WSDL file is not needed for this message structure, since the SOAP client code provides the name of the operation and the values for the arguments. The argument and return types are xsd:string. For Axis, data type information that is normally in a WSDL is instead in the SOAP envelopes.

In summary, achieving interoperable SOAP is complicated because:

  • Microsoft client to Java server:
    - Java server correctly handles request message: it ignores the SOAPAction in the HTTP header and cares what the arguments of the operation are called. Also, it does not need to get the data types of the arguments from the message.
    - MS client correctly handles response message: it ignores the type information in the response. The problem: the Java Server may not produce a WSDL that the MS client needs.
  • Java client to Microsoft server: Microsoft server does not handle the request message because it is missing a value for SOAPAction, and the name of the argument, arg0, is wrong. A Java client might not use WSDL and does not know the data type of the response.

    Interoperability Solutions
    Fortunately, interoperability between Microsoft- and Java-based SOAP implementations is possible. In fact, with Java products like Axis (first beta release on March 15, 2002) it is becoming easier. The solution to using a Microsoft SOAP client with a Java-based SOAP server requires the creation of a WSDL file for the client. There are at least two solutions to using a Java-based SOAP client with a Microsoft SOAP server. The first approach is to have the client read a WSDL to identify how to structure the send message. The second, less attractive, approach is to hard code details, like the argument names and types. While this approach is tedious and less maintainable, it may be necessary in some cases, like when a Java-based SOAP implementation cannot parse a WSDL file.

    Microsoft SOAP Client to Java Server
    Using a Microsoft SOAP client with a Java-based SOAP server is straightforward as long as the SOAP server has a WSDL file. Consider the scenario where a user submits form data from a Web page to an ASP page. The ASP page then makes a SOAP request to an Axis Servlet (see Figure 2).

     

    The code in the ASP page has two parts. The first part mainly sets which WSDL file is to be used, depending on whether this page should use a Microsoft or Java SOAP server. The second part creates a SoapClient and initializes it with a WSDL file. The call to ClientProperty enables "server safe" loading of the WSDL file. Once the SOAP client initializes the WSDL file, using mssoapinit, the client can then invoke any operation in the first port of the first service of the WSDL file. Recall that in WSDL terminology, a port is a group of operations, a service is a group of ports, and a WSDL file can specify more than one service. So while it is also possible to name a specific service and port in the mssoapinit call, a SoapClient object represents only one port (group of operations) of one service. The line inside the try-block calls the getCondition operation, passing in the value of the city obtained from the HTML form in the Web page.

    Listing 1 is from the file weather_ms Client.asp (source code for this article is available at www.sys-con.com/webservices/sourcec.cfm). Notice that this ASP code works whether it sends a request to either a Microsoft or a Java SOAP server. The trick when using a servlet is to create a WSDL file that this client code can use. Fortunately, Axis can automatically generate a WSDL file from Java source code. Point your browser to the URL of the SOAP request handler, adding a WSDL to the URL. A request handler is simply a normal Java source file that is given a .jws, instead of the normal .java, extension. Axis also includes command-line utility to generate a WSDL from a Java source file. IBM, who along with Microsoft authored the WSDL specification, developed this utility, and it is available independent of Axis.

    Unfortunately, the generated WSDL file does not always work without modification. It will work with ASP running under IIS 5.0, but you will probably have to modify it to work with ASP for PWS 4.0, as shown below. In the binding section of the WSDL, there is an element named operation in the http://schemas.xmlsoap.org/wsdl/soap/namespace. The value of this element's soapAction attribute goes in the HTTP header of the SOAP request. The generated WSDL sets the value of the soapAction to the empty string. The ASP SOAP client running under PWS expects soapAction to have a value; it can be nearly anything since the Java SOAP server does use it.

    The minor edit to the WSDL file, javaServer\WeatherService.wsdl, generated by Axis, looks like this:

    <wsdlsoap:operation soapAction="thisIsForPWS" />

    Component Design
    The component that provides the current weather condition, whether written in Java or Visual Basic, has the same design. It is a class named Weather with just one method, named getCondition.

    Component Coding
    The Java and Visual Basic code that implement this class have a similar structure, and both use the city name to randomly generate a weather condition.

    Looking at the Java source code in Listing 2, notice that the class has two parts. The first defines a list of possible weather conditions and the second is the getCondition method. It initializes a Random object based on the hash code of the city named in the variable where. This code is from the file javaServer\Weather.jws. (Remember that in Axis, Java files have the .jws extension instead of .java. Inside, the Java file has the normal structure.)

    Java SOAP Client to Microsoft Server
    When a client uses a WSDL file, the JSP code looks much like ASP SOAP client code (discussed earlier). Additionally, the Java client could configure the SOAP service without a WSDL file. With both of these approaches a Web page sends user input to a JSP page, which in turn uses an ASP SOAP server to satisfy the request. The SOAP server uses a COM object written in Visual Basic to produce the return data. Microsoft's SOAP Toolkit includes a utility that generates the ASP SOAP Server page and the WSDL from a COM object (see Figure 3).

     

    The JSP page, which uses a WSDL, has two sections. Skipping the page import statements, for now, the first section sets up the WSDL-related parameters, depending on whether it uses a Java or Microsoft SOAP server. The second section creates a SOAP service object based on a service named WSDL file. Remember that WSDL can specify more than one service. From the service object, the code next creates a call object that represents a single operation. Since a WSDL file groups operations into ports, the createCall method must specify which port the operation is in. The last call simply invokes the getCondition operation, passing the value for the city and getting the current in return. Listing 3 is from the file weather_javaClient.jsp.

    Most of Listing 3, though written for Axis's SOAP implementation, applies to other Java-based SOAP implementations. Those familiar with Java can tell from the import statements of the first five lines that nothing in the code is unique to Axis. The classes in the import statements beginning with java or javax are standard or standard extension Java classes, and all future Java-based SOAP implementations should use them.

    The logic for the Weather class in Visual Basic is the same as the Java code described in the previous section. It has an additional method to generate a hash code from the city.

    Example Application
    To start the sample applications, load index.html into a browser. It should look like Figure 4. Enter a city, configure the SOAP client and server, and click the "Investigate" button.

     

    If you enter Arlington and choose the JSP client and the ASP Server, the resulting Web page should look like Figure 5. Repeat the process, using other names and other SOAP applications.

     

    Application Setup
    System Requirements

    The example in this article requires several technologies. In addition to Microsoft's Internet Information Server (IIS) or Personal Web Server (PWS), and a browser such as Internet Explorer, the samples for this article use the following, freely available, products.

  • Microsoft SOAP Toolkit 2.0 SP2 (http:// msdn.microsoft.com/downloads/default.asp?URL=/code/sample.asp?url=/ms dn-files/027/001/580/msdncompositedoc.xml)
  • Visual Basic Run-Time (http://download.microsoft.com/download/ vb60pro/Redist/sp4/win98/EN-US/VBRun60sp4.exe)
  • Sun Java 2 SDK, Standard Edition v1.4 (http://java.sun.com/j2se/1.4/download.html)
  • Apache Jakarta Tomcat v4.0 (http://jakarta.apache.org/builds/jakarta-tomcat-4.0/release/v4.0.6/bin/jakarta-tomcat-4.0.6-LE-jdk14.zip)
  • Apache Axis beta 3 (http://xml.apache.org/axis)

    To install the Microsoft SOAP Toolkit, the Visual Basic Run-Time, and the Java 2 SDK, double-click on each of the downloaded files and accept the default installation. Here is a simple procedure for setting up Tomcat and Axis:

  • Persistently (may require a reboot) set the environment variable: JAVA_HOME=C:\j2 sdk1.4.0_01.
  • Unzip the Tomcat and Axis downloads (jakarta-tomcat-4.0.4-LE-jdk14.zip and xml-axis-beta3-bin.zip) into a folder of your choice; the examples in this article use C:\tomcat_ axis.
  • Copy the contents of C:\tomcat_axis\ axis-1_0\lib into C:\tomcat_axis\jakarta-tomcat-4.0.4-LE-jdk14\lib.

    Once your system is set up, as described in the System Requirements Section, use the following steps to set up the application.

  • Unzip the iSoap.zip file to C:\tomcat_axis \jakarta-tomcat-4.0.4-LE-jdk14\webapps.
  • Set up Web sharing on C:\tomcat_axis\jak arta-tomcat-4.0.4-LE-jdk14\webap ps\iSoap:
    - Right-click on the folder.
    - Select Properties
    - In the Web Sharing tab, click on Share this folder.
    - Add the alias iSoap.

  • Register WeatherProject.dll by double-clicking registerDll.bat in C:\tomcat_axis\ jakarta-tomcat-4.0.4-LE-jdk14\web pps\iSoap\ms Server. (For Windows 98, you may have to type [or copy and paste] regsvr32 C:\tomcat_axis\jakarta-tomcat-4.0.4-LE-jdk14\ webappsiSoap\msS erver \WeatherProject. dll into the Wind ows Start/Run... dialog box.)
  • Start Tomcat by double-clicking C:\tomcat_axis\jakarta-tomcat-4.0.4-LE-jdk14\ bin\startup.bat.
  • Load C:\tomcat_axis\jakarta-tomcat-4.0 .4-LE-jdk14\webapps\iSoap\index.html into a browser.

    Conclusion
    Interoperability between Microsoft- and Java-based implementations of SOAP continues to be difficult, but possible. Until the W3C produces a stable SOAP recommendation, it is not surprising that there are difficulties. The interoperability issues stem mostly from the use (or non-use) of the WSDL, as well as the differences in the SOAP messages. Microsoft SOAP uses WSDL, most Java-based SOAP does not need it and the W3C has decided not to include WSDL with the SOAP recommendation. For RPC-oriented messages over HTTP, Microsoft SOAP servers expect request messages to have operation information in the HTTP header and use specific names for operation arguments. Java-based SOAP servers do not use HTTP header information, and do not care what name is used for the operation arguments. Java-based SOAP clients and servers put data type information into the request and response messages; Microsoft clients and servers do not.

    Solving these interoperability problems is possible. Creating a WSDL for Java-based SOAP implementations solves many of the problems. The samples in this article used a Java-based SOAP implementation from Apache, named Axis (in beta at the time of this writing), which does support WSDL. While the samples used Axis, they are representative of the kind of solution required for any Java-based SOAP implementation.

    A Java-based SOAP implementation is quite flexible. It does not require WSDL, and a developer has a lot of control in structuring the client calls. The Microsoft-based implementation, while not as flexible because it requires the WSDL, is a solid implementation that effectively uses WSDL to simplify a developer's task in writing client-side code.

  • About Keith Shaffer

    Keith Shaffer spent 12 years in th aerospace industry, most in the R&D department of Hughes aircraft Compnay, then began traiing and consulting on a range of technologies. For the last several years he has specialied in object-oriented analysis and design, Java, and XML technologies

    Comments (3) View Comments

    Share your thoughts on this story.

    Add your comment
    You must be signed in to add a comment. Sign-in | Register

    In accordance with our Comment Policy, we encourage comments that are on topic, relevant and to-the-point. We will remove comments that include profanity, personal attacks, racial slurs, threats of violence, or other inappropriate material that violates our Terms and Conditions, and will block users who make repeated violations. We ask all readers to expect diversity of opinion and to treat one another with dignity and respect.


    Most Recent Comments
    Frank Wilhoit 01/17/03 08:35:00 AM EST

    Your statement that the W3C "has not embraced using WSDL as a standard way of describing Web services" is false. Please see The W3C Web Services Architecture Working Draft (http://www.w3.org/TR/ws-arch/), Section 2, and Section 4.2.4.

    nm 11/06/02 04:44:00 PM EST

    nm, Found it

    Frusterated 11/06/02 04:21:00 PM EST

    I cannot find the zip referred to in this article. I would very much like to set up this demo and see it in action.

    The files I am looking for is the Isoap.zip that is mentioned where can I get a copy?

    Cheers
    Mike