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. |
![]() |