6 Creating Dynamic Proxy Clients

A dynamic proxy client enables a Web Service client to invoke a Web Service based on a service endpoint interface (SEI) dynamically at run-time without using clientgen. The steps to create a dynamic proxy client are outlined in the following table. For more information, see the javax.xml.ws.Service Javadoc at http://java.sun.com/javase/6/docs/api/javax/xml/ws/Service.html.

Table 6-1 Steps to Create a Dynamic Proxy Client

Step Description


Create the javax.xml.ws.Service instance.

Create the Service instance using the Service.create method.

You must pass the service name and optionally the location of the WSDL document. The method details are as follows:

public static Service create (QName serviceName) throws javax.xml.ws.WebServiceException {}
public static Service create (URL wsdlDocumentLocation, QName serviceName) throws javax.xml.ws.WebServiceException {}

For example:

URL wsdlLocation = new URL("http://example.org/my.wsdl");
QName serviceName = new QName("http://example.org/sample", "MyService");
Service s = Service.create(wsdlLocation, serviceName);


Create the proxy stub.

Use the Service.getPort method to create the proxy stub. You can use this stub to invoke operations on the target service endpoint.

You must pass the service endpoint interface (SEI) and optionally the name of the port in the WSDL service description. The method details are as follows:

public <T> T getPort(QName portName, Class<T> serviceEndpointInterface) throws javax.xml.ws.WebServiceException {}
public <T> T getPort(Class<T> serviceEndpointInterface) throws javax.xml.ws.WebServiceException {}

For example:

MyPort port = s.getPort(MyPort.class);