Client Code

In contrast to the service code, writing client code does require interfacing with the Apache SOAP API. Regardless of the complexity, however, client code generally follows the same five steps:

  1. Create an RPC Call object. The Call object encapsulates all the details for invoking a remote SOAP service. For example, it includes the SOAP service name and the method name to invoke.

  2. Build a list of parameters to pass to the remote service. Apache SOAP includes built-in support for passing a large number of data types, including primitive data types, strings, vectors, and arrays. As we will see in Chapter 5, Apache SOAP also supports the passing of JavaBeans and literal XML documents.

  3. Invoke the remote method. Behind the scenes, the client packages the relevant data into a SOAP request, sends it to the SOAP server, and receives and parses the SOAP response.

  4. Check for any errors within the SOAP response.

  5. Extract the return value from the SOAP response.

The complete client code for the “Hello, SOAP!” application is shown in Example 4-2.

Example 4-2. HelloClient.java
package com.ecerami.soap;

/**
 * "Hello, SOAP!" SOAP Client
 * usage:  java HelloClient first_name
*/
import java.net.*;
import java.util.Vector;
import org.apache.soap.SOAPException;
import org.apache.soap.Fault;
import org.apache.soap.Constants;
import org.apache.soap.rpc.Call;
import org.apache.soap.rpc.Parameter;
import org.apache.soap.rpc.Response; public class HelloClient { /** * Static Main method */ public static ...

Get Web Services Essentials now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.