So How Do We Develop a SOAP Client?


Developing a client is a little more involved.
The basic steps for creating a client which interacts with a SOAP RPC-based service are as follows:

  1. Obtain the interface description of the SOAP service, so that you know what the signatures of the methods that you wish to invoke are. If you are calling a service implemented by somebody else, there is usually a WSDL file made available by the service implementor, which gives the signatures of methods for that service. You can either look at the WSDL file (or at some other interface definition format) or directly at its implementation. XMethods.net has a comprehensive collection of web services available for free use.
  2. Create the Call object ( org.apache.soap.rpc.RPCMessage.Call), which is the main interface to the underlying SOAP RPC code as follows:
    Call  call = new Call ( );
  3. Set the target URI into the Call object using the setTargetObjectURI(...) method. Pass in the URN that the service used to identify itself in its deployment descriptor and set the method name.
    call.setTargetObjectURI ("urn:xmethods-add-numbers");
    call.setMethodName ("add");
  4. Create any Parameter objects necessary for the RPC call and set them into the Call object using the setParams(...) method.
    Vector params = new Vector ();
    params.addElement (new Parameter("num1", Integer.class, new Integer(num1), null));
    params.addElement (new Parameter("num2", Integer.class, new Integer(num2), null));	    
    call.setParams (params);
  5. Execute the Call object's invoke(...) method and capture the Response object which is returned from invoke(...). The invoke(...) method takes in two parameters, the first is a URL which identifies the endpoint at which the service resides and the second is the value to be placed into the SOAPAction header.
    Response resp = call.invoke(url,""); 
  6. And finally, extract any result or returned parameters using the getReturnValue() or getParams() methods.
    Parameter result = resp.getReturnValue ();
    Click here to view AddClient.java


    Next --> Benefits of SOAP