LanguagesXMLGetting started with SOAP

Getting started with SOAP content and product recommendations are editorially independent. We may make money when you click on links to our partners. Learn More.

With backing from industry giants like Microsoft and IBM, the Simple Object Access Protocol (SOAP) promises to find its way into many applications in 2001. SOAP provides a mechanism for programs to pass messages to each other. This is very similar to RPC (Remote Procedure Calls), so the concept is not new. What’s interesting about SOAP is that it is based on open and simple protocols. Messages are based on XML and can use HTTP as their transport. Since most firewalls allow HTTP traffic to go through, your applications can communicate with other applications outside of your enterprise (partners, suppliers, customers, etc.). This is where SOAP is going to shine by providing a link between disparate applications and creating business value from such integration.

It is easy to get started with SOAP. There are plenty of implementations for different programming languages. One such implementation is from Apache Software Foundation ( For the Apache implementation, you need four things to get started with SOAP:

1) A Java compiler and JVM (JDK 1.3)
2) The SOAP distribution from Apache (
3) Xerces XML Parser from Apache (
4) A Servlet Engine (e.g., Tomcat;

The SOAP distribution from Apache supports most of SOAP 1.1 specification. URLs are used to uniquely identify remote objects. XML messages are POSTed (using HTTP) to a JSP page called rpcrouter. This will in turn create a Call object, finds the object (using a ServiceManager), and invokes the appropriate method. The return value is captured as a Result object and sent back. During this process, marshalling and unmarshalling of XML data occurs which is based on the Serialization API.

Once you install Apache SOAP, in the lib directory, you’ll find soap.jar which you should add to your CLASSPATH. The other thing you need to be careful about is the XML parser. Apache SOAP requires Xerces 1.1.2 or higher as this version implements DOM level 2. If you already have another parser in your system, you need to make sure that the xerces.jar is in front of your CLASSPATH. This will save you from headaches down the road.

If you are using Tomcat (I strongly recommend you do), then instructions for configuring it for SOAP is provided as part of the Apache SOAP distribution. Once you make the changes, you can access the administration tool using a URL like: http://localhost:8080/soap. This assumes you are deploying Tomcat on your local machine using port 8080. Using the admin tool you can deploy any of the three sample services that ship with Apache SOAP. They are located in the samples directory. In each application directory, there is a file called descriptor.xml. You can use the information provided in that file to fill in the form provided by the admin tool as part of the deployment process.

The stockquote sample application provides a simple service that accepts a stock symbol and returns a 20-minute delayed price. Take a look at the file This is the client making a SOAP call to the service. The basic steps for invoking a call are outlined here. Note that the url argument in the invoke() method refers to the rpcrouter dispatcher which most likely is running on your local machine. After you create an empty instance of the Call, you populate it and then make the actual request using the invoke() method. The result is captured in a Response object which you can check for errors and then print its value.

<p><font color=”#0000FF”><span>call call = new Call ();<br>call.setTargetObjectURI ("urn:xmltoday-delayed-quotes");<br>call.setMethodName ("getQuote");<br>call.setEncodingStyleURI(encodingStyleURI);<br>Vector params = new Vector ();<br>params.addElement (new Parameter("symbol", String.class, symbol,null));<br>call.setParams (params);<br> <br>Response resp = call.invoke (url, "" );<br> <br>if (resp.generatedFault ()) {<br><span>    </span>Fault fault =resp.getFault ();<br><span>    </span>System.out.println (fault.getFaultString());<br>} else {<br><span>    </span>System.out.println (result.getValue());<br></span>}</font></p>

The service being invoked is shown in the file As you study the code you will see that the method getQuote() actually makes a regular HTTP connection to the Web site and retrieve the pricing information.

This has been a glimpse into SOAP and what it can bring to your applications. I encourage you to study the other sample applications and then create your own service. Many are predicting 2001 to be the year of services, so you might as well get ready now.

Piroz Mohseni

Get the Free Newsletter!

Subscribe to Developer Insider for top news, trends & analysis

Latest Posts

Related Stories