Writing a Java Client Wrapper for a RPC-encoded Web Service

Writing a Java wrapper for non-WS-I-compliant Web services requires that you have the proper environment configured on your computer. There are other options available, but these examples use Eclipse 3.6 (Helios) as the Java IDE.



A Java Integrated Development Environment (IDE). This example uses Eclipse 3.6 (Helios).

Basic steps

  1. Generate the client stub source files using Axis
  2. Write and compile the service wrapper client
  3. Test the class

Generating the client stub source files

Writing and compiling the service wrapper client

Using a text editor and Javac Java compiler you could use the generated source code to write a client. If you executed the call to javac from the C:\temp\wsdlgencleint folder, it would look similar to this:

javac -cp
%AXIS_HOME%/lib/wsdl4j-1.5.1.jar" -d ".\classes" .\src\com\attachmate\wrappedservices\*.java

However, using a Java IDE, such as Eclipse 3.6 (Helios), makes things much easier.

Using Eclipse 3.6 Helios to write the wrapper client

  1. Open Eclipse and create a Java project.

    New Eclipse project

    Create new Eclipse project

  2. To add the generated source files to the project, copy the com folder from C:\temp\wsdlgenclient\src to the source folder in the Eclipse Project Explorer.

    Add source files to project
    Any errors that occur will be fixed in the next step.

  3. To fix the errors, right-click on the project in the Project Explorer, and select Properties.

    Open Properties panel

  4. Click on the Libraries tab, and then Add External JARs.... In the file dialog box that opens navigate to the lib folder in your Axis installation and add all the jars listed in the Javac command.

    After you dismiss the Properties dialog box the errors should resolve and the Project Explorer should look like this:

    Project Explorer classes
    At this point in the process, there are only stub classes. To call the Web service's operations you need a wrapper class.

  5. Right-click on the com.attachmate.wrappedservices package in the Project Explorer, select New, and then class.

  6. Enter the name ServiceWrapper for the class and then click Finish.

    Java class dialog box

  7. To this new class, add a variable of type CICSAcctsDemoSoapBindingStub named stub and a constructor with no parameters.

Example code for the wrapper class

// sample source code
package com.attachmate.wrappedservices;
import java.rmi.RemoteException;
import javax.xml.rpc.ServiceException;
public class ServiceWrapper 
	CICSAcctsDemoSoapBindingStub stub;
	public ServiceWrapper()
			CICSAcctsDemoSessionServiceLocator locator = new 							
			stub = (CICSAcctsDemoSoapBindingStub)locator.getCICSAcctsDemo();
		catch (ServiceException afe)
	public GetAccountDetailRecord[] getAccountDetail(int acctNum)
		GetAccountDetailRecord[] retVal = null;
			retVal = stub.getAccountDetail(acctNum);
		catch (RemoteException re)
		return retVal;

Other operations will require similar wrapper methods. Next create a test class by adding a new class as before only this time with a main method. In the main method of the new class instantiate an instance of ServiceWrapper and test the wrapper by calling ServiceWrapper.getAccountDetail(int acctNum).

This is an example of source code for the test class:

// sample source code
package com.attachmate.wrappedservices;
public class ServiceWrapperTestRunner
	public static void main(String[] args) 
		ServiceWrapper wrapper = new ServiceWrapper();
		GetAccountDetailRecord[] records = wrapper.getAccountDetail(20000);
		for (GetAccountDetailRecord record : records)
			System.out.println("Name on account with account number 20000 is " + 
	record.getFirstName() + " " + record.getLastName());

Running the test class

To run the test class:

Related Topics
Bullet Deploying the Java client as a WS-I compliant Web service
Bullet Writing and Deploying a .NET (C Sharp) client wrapper for a RPC-encoded Web service