FileDocCategorySizeDatePackage
CounterClient.javaAPI DocExample2884Tue Oct 09 11:03:40 BST 2001com.ecerami.soap

CounterClient

public class CounterClient extends Object
A Sample SOAP Client Retrieves Current Counter value from CounterService Illustrates Session v. Application Scope

Fields Summary
private Call
call
Constructors Summary
public CounterClient()
Constructor Create reusable Call object

    call = new Call();
  
Methods Summary
public intgetCounter()
getCounter Method


    // Set Encoding Style to standard SOAP encoding
    call.setEncodingStyleURI(Constants.NS_URI_SOAP_ENC);

    // Set Object URI and Method Name
    call.setTargetObjectURI ("urn:examples:counterservice");
    call.setMethodName ("getCounter");

    //  Set the URL for the Web Service
    URL url = new URL ("http://localhost:8080/soap/servlet/rpcrouter");

    // Invoke the Service
    Response resp = call.invoke (url, null);

    // Check for Success
    if (!resp.generatedFault()) {
      // Extract Return value
      Parameter result = resp.getReturnValue ();
      Integer counter = (Integer) result.getValue();
      return counter.intValue();
    }
    //  Check for Faults
    else {
        //  Extract Fault Code and String
        Fault f = resp.getFault();
        String faultCode = f.getFaultCode();
        String faultString = f.getFaultString();
        throw new CounterException (faultCode+": "+faultString);
    }
  
public static voidmain(java.lang.String[] args)
Static Main method

    System.out.println ("Session/Application Counter:  SOAP Client");
    CounterClient counterClient = new CounterClient();
    counterClient.process();
  
public voidprocess()
Start counting

    try {
      for (int i=0; i<5; i++) {
        int counter = getCounter ();
        System.out.println ("Counter:  "+counter);
      }
    } catch (CounterException e) {
      System.err.println (e);
    } catch (SOAPException e) {
      System.err.println (e);
    } catch (MalformedURLException e) {
      System.err.println (e);
    }