Chapter 5 Client Design
223
invocation. Code Example 5.7 illustrates using the DII approach for locating and
accessing a service. It shows how the
Call
interface used by DII is configured
with the property values required to access the order tracking Web service. The
values set for these properties may have been obtained from a registry. Keep in
mind that using DII is complex and often requires more work on the part of the
client developer.
Service service = //get service
QName port = new QName("urn:OpcOrderTrackingService",
"OrderTrackingIntfPort");
Call call = service.createCall(port);
call.setTargetEndpointAddress(
"http://localhost:8000/webservice/OtEndpointEJB");
call.setProperty(Call.SOAPACTION_USE_PROPERTY,
new Boolean(true));
call.setProperty(Call.SOAPACTION_URI_PROPERTY,"");
call.setProperty(ENCODING_STYLE_PROPERTY, URI_ENCODING);
QName QNAME_TYPE_STRING = new QName(NS_XSD, "string");
call.setReturnType(QNAME_TYPE_STRING);
call.setOperationName(
new QName(BODY_NAMESPACE_VALUE "getOrderDetails"));
call.addParameter("String_1", QNAME_TYPE_STRING,
ParameterMode.IN);
String[] params = {orderId};
OrderDetails = (OrderDetails)call.invoke(params);
Code Example 5.7
J2SE Client Using DII to Access a Web Service
5.3.3 Stubs and Call Configuration
Developers may want to configure an instance of a stub or a
Call
interface prior to
invoking a service or may prefer to allow the configuration to take place dynami
cally at runtime. Often, the developer configures the stub or
Call
interface prior to
invoking the service when the service requires basic authentication. For example, a
J2SE client application needs to set a user name and password in the stub or
Call
just before invoking the service; the service requires these two fields so that it can
authenticate the client. In other cases, the developer may want flexibility in specify
ing the endpoint address to use for a particular service, depending on network avail
New Page 1