Stub-based model client  Dynamic invocation interface client

Chapter 9: Developing Web Service Clients

Dynamic proxy client

The dynamic proxy client creates dynamic proxy stubs at runtime using JAX-RPC client APIs. The client gets the service information from a given WSDL document. It uses the service factory class to create the service based on the WSDL document and obtains the proxy from the service.

The significant JAX-RPC client APIs used are:


Dynamic proxy client example

This section contains a listing of a sample dynamic proxy client:

package client;

import java.net.URL;
import javax.xml.rpc.Service;
import javax.xml.rpc.ServiceFactory;
import javax.xml.namespace.QName;


public class JAXRPC_DynClient
{
    public static void main(String[] args)
    {
        try
        {
	/*
	 * URL to the Service's WSDL document
	*/
            URL wsdl = new URL("http://localhost:8080/ws/services/AddNumbers?wsdl");
            String namespaceURI = "urn:simpleJavaClass.AddNumbers";
            String serviceName = "AddNumbers";
            String portName = "AddNumbers";
            int num1 = 10;
            int num2 = 20;


            ServiceFactory factory = ServiceFactory.newInstance();

            /*
* Create a service using the WSDL document
*/
            Service service = factory.createService(wsdl, new QName(namespaceURI, serviceName));

	/*
	 *  Get the proxy by calling getPort method from an instance of Service.
	*/
            AddNumbers_Port port = (AddNumbers_Port)service.getPort(new QName(namespaceURI, portName), AddNumbers_Port.class);
            int value= port.add(num1, num2);
            System.out.println("Result of adding " + num1 + " and " +  num2  + " is: " + value);

        }
        catch (Exception e)
        {
            e.printStackTrace();
        }
    }

}




Copyright © 2005. Sybase Inc. All rights reserved. Dynamic invocation interface client