Chapter 5 Client Design
221
access to the naming services available to clients in a J2EE environment through
JNDI APIs. See Code Example 5.3.
Stub stub = (Stub)(new OpcOrderTrackingService_Impl().
getOrderTrackingIntfPort());
OrderTrackingIntf port = (OrderTrackingIntf)stub;
Code Example 5.3
Accessing a Service with a Stub in J2SE and J2ME Environments
In addition, a J2SE or J2ME client can access a service by using the
javax.xml.rpc.ServiceFactory
class to instantiate a stub object. Code Example
5.4 shows how a J2SE client might use a factory to locate the same order tracking
service.
ServiceFactory factory = ServiceFactory.newInstance();
Service service = factory.createService(new QName(
"urn:OpcOrderTrackingService", "OpcOrderTrackingService"));
Code Example 5.4
Looking Up a Service in J2SE and J2ME Environments
Similarly, Code Example 5.5 shows how a J2SE application might use a
dynamic proxy instead of a stub to access a service.
...
ServiceFactory sf = ServiceFactory.newInstance();
String wsdlURI =
"http://localhost:8001/webservice/OtEndpointEJB?WSDL";
URL wsdlURL = new URL(wsdlURI);
Service ots = sf.createService(wsdlURL,
new QName("urn:OpcOrderTrackingService",
"OpcOrderTrackingService"));
New Page 1