January 20, 2021
Hot Topics:

Developing JAX-RPC-Based Web Services Using Axis and SOAP

  • By Rajesh Sumra
  • Send Email »
  • More Articles »

OrderProcessing Web Service Client

Dynamic client

Dynamic client is analogous to looking up and invoking the Java class methods using the reflection APIs.

Here, all the information, such as target endpoint, method parameters, and so forth has to be set explicitly. The code shown in Listing 5 will tell how to write a dynamic client for invoking the updateOrder method, in the OrderProcessing Web service.

Listing 5: Dynamic Client

package sample.client;
import org.apache.axis.client.Call;
import org.apache.axis.client.Service;
import org.apache.axis.encoding.XMLType;
import javax.xml.rpc.ParameterMode;
import javax.xml.rpc.encoding.*;
import javax.xml.namespace.QName;
import java.util.*;
import sample.*;

 * This class illustrates how to use the JAX-RPC API to invoke
 * the Order Processing Web service dynamically
public class DynamicClient {
  public static void main(String[] args) throws Exception {

  // create service factory
  ServiceFactory factory = ServiceFactory.newInstance();

  // define qnames
  String targetNamespace = "OrderProcessingService";

  QName serviceName = new QName(targetNamespace,

  QName portName = new QName(targetNamespace,
  QName operationName = new QName(targetNamespace, "updateOrder");

  // create service
  Service service = new Service();
  Call     call   = (Call) service.createCall();
   Qname qn       = new Qname(targetNamespace, "OrderHolder");

  call.registerTypeMapping(OrderHolder.class, qn,
  new org.apache.axis.encoding.ser.BeanSerializerFactory
      (OrderHolder.class, qn),
  new org.apache.axis.encoding.ser.BeanDeserializerFactory
      (TicketHolder.class, qn));

  // set port and operation name

  // add parameters
  call.addParameter( "arg1", serviceName, ParameterMode.INOUT );
  call.setReturnType( XMLType.XSD_STRING );

  Order order = new Order ();
  order.setOrderDate("03 March 2003");

  // set end point address

  // Invoke the WebService
  String result = (String) call.invoke( new Object[] { order } );
  System.out.println("result : " +result);

  Map outparams = call.getOutputParams();

  System.out.println("Got the outparams");


Running the Client

To run the client, use this command:

<Prompt>java -cp %AXISCLASSPATH% sample.client.DynamicClient

The result will be:

Got the outparams (as mentioned in client we developed)


This article tried to demystify Web services and tell how easy and economic it is to develop jax-rpc based Web services using an open source tool—Axis from Apache. This article elaborated on "How to Develop" JAX-RPC based Web services in a way that gives the developer a freedom of writing a client and Web service that hides all the complexities of serializing objects in an on-the-wire XML format and, for developers, it will simply appear to be just a Java method invocation. As a next step to this article, I will deal with other methodologies and technologies involved in Web services.

About the Author

Mr. Rajesh Sumra has been working as a Senior Software Engineer for Hewlett-Packard. He has around three years of industry experience. He has extensively worked on Web service technologies such as WSDL, SOAP, and UDDI. Currently, he is involved in designing and developing a Web services-based framework for a mobile infrastructure for HP Labs, Japan. He holds a Masters degree in Information Technology from the Indian Institute of Information Technology, Bangalore. He can be reached at rajeshsumra@yahoo.com.


Page 3 of 3

This article was originally published on July 18, 2003

Enterprise Development Update

Don't miss an article. Subscribe to our newsletter below.

Thanks for your registration, follow us on our social networks to keep up-to-date