222
Developing Client Applications to Use a Web Service
OrderTrackingIntf port = (
OrderTrackingIntf)ots.getPort(new QName(
"urn:OpcOrderTrackingService", "OrderTrackingIntfPort"),
OrderTrackingIntf.class);
...
Code Example 5.5
J2SE Client Dynamic Proxy Service Lookup
Code Example 5.5 illustrates how a J2SE client might program to interfaces
that are portable across JAX RPC runtimes. It shows how a J2SE client uses a
ServiceFactory
to look up and obtain access to the service, represented as a
Service
object. The client uses the qualified name, or
QName
, of the service to
obtain the service's port. The WSDL document defines the
QName
for the service.
The client needs to pass as arguments the
QName
for the target service port and the
client side representation of the service endpoint interface.
By contrast, Code Example 5.6 shows how a J2EE client might use a dynamic
proxy to look up and access a service. These two examples show how much
simpler it is for J2EE clients to look up and access a service than it is for J2SE cli
ents, since a JNDI lookup from the
IntialContext
of an existing service is much
simpler than configuring the parameters for
ServiceFactory
. The J2EE client just
invokes a
getPort
call on the client side representation of the service endpoint
interface.
Context ic = new InitialContext();
Service ots =
(Service) ic.lookup(
"java:comp/env/service/OpcOrderTrackingService");
OrderTrackingIntf port = (OrderTrackingIntf)ots.getPort(
OrderTrackingIntf.class);
Code Example 5.6
Using a Dynamic Proxy in a J2EE Environment
A J2SE client using the DII approach might implement the code shown in
Code Example 5.7 to look up the same service at runtime. DII communication
supports two invocation modes: synchronous and one way, also called fire and
forget. Both invocation modes are configured with the
javax.xml.rpc.Call
object. Note that DII is the only communication model that supports one way
New Page 1