Introduction  Dynamic proxy client

Chapter 9: Developing Web Service Clients

Stub-based model client

The stub-based model generates local stub classes for the proxy from a WSDL document. This is the model used by the WST development tool to create a Web service client. When you change the WSDL document, you must regenerate the stubs. WST provides tools to generate and compile stubs. See “Creating and managing Web service clients” and wsdl2Java. Along with the stubs, the tools generate additional classes, and a service definition interface (SDI), which is the interface that is derived from a WSDL’s portType. This is the interface you use to access the operations on the Web service. The combination of these files are called client-side artifacts. Client-side artifacts are a collection of files on the client-side that handle communication between a client and a Web service. Generated client-side artifacts must include:


stub-based example

This stub-based client example can be found in %JAGUAR%\sample\wst_samples\JavaClassClient\client\AddClient.java.

package client;
import java.rmi.RemoteException;
import javax.xml.rpc.ServiceException;
/**
* @author Sybase
*
* A sample client to access the add method in the service.
* The add method returns the addition of two numbers
* which is calculated by the webservice AddNumbers.
*
*/
public class AddClient
{
    public static void main(String[] args)
    {
        AddNumbers_ServiceLocator context;
        AddNumbers_Port client;
        try
        {
            int num1 = 10;
            int num2 = 10;
            context = new AddNumbers_ServiceLocator();
            client = context.getAddNumbers();

            if (args.length > 0)
            {
                num1 = new Integer(args[0]).intValue();
                if (args.length >1)
                {
                    num2 = new Integer(args[1]).intValue();
                }
            }
            int value= client.add(num1, num2);
            System.out.println("Result of adding " + num1 + " and " +  num2  + " is: " + value);
        }
        catch (ServiceException ex1)
        {
            ex1.printStackTrace();
        }
        catch (RemoteException ex2)
        {
            ex2.printStackTrace();
        }
    }
}




Copyright © 2005. Sybase Inc. All rights reserved. Dynamic proxy client