Defining the Client ID During Port Initialization

Invoking Web Services 6-15 The following sections describe the methods for managing the client ID: ■ Section 6.6.1, Defining the Client ID During Port Initialization ■ Section 6.6.2, Accessing the Server-generated Client ID ■ Section 6.6.3, Client Identity Lifecycle

6.6.1 Defining the Client ID During Port Initialization

To provide its client ID, the Web service client can pass an instance of the ClientIdentityFeature containing the client ID to the Web service port at initialization time. The client ID must be unique within the Web application or EJB that contains the client. It is recommended that the client ID appropriately reflect the business purpose. In order to ensure that the client ID is unique, the system prepends the names of the containing server, application, and component Web application or EJB to the client ID. The following example demonstrates this method of specifying the client ID. It is recommended that you close the client instance once all processing has been complete, as shown. This example is excerpted from Web Service Client Best Practices Example in Programming Advanced Features of JAX-WS Web Services for Oracle WebLogic Server. Example 6–2 Example of Specifying the Client ID During Port Initialization import javax.servlet.; import javax.xml.ws.; import weblogic.jws.jaxws.client.ClientIdentityFeature; . . . public class BestPracticeAsyncClient Table 6–2 Methods of ClientIdentityFeature for Setting and Accessing Client ID Method Description getClientID Gets the currently defined client ID for the Web service port. setClientID Sets the client ID for the Web service port. In addition, you can set the client ID by passing it as an argument when instantiating the ClientIdentityFeature object. For example: ClientIdentityFeature clientIDFeature = new ClientIdentityFeatureMyBackendServiceAsyncClient; dispose Disposes the client ID. If a client ID is not disposed of explicitly, it will be done when the container for the client instances that use the client ID is deactivated for example, the host Web application or EJB is deactivated. For more information, see Section 6.6.3, Client Identity Lifecycle. Notes: Care should be taken when choosing a client ID. If a client instance is created with the same client ID as an existing client instance, the two client instances will be treated as the same instance. No exception will be thrown to alert you to the duplication. 6-16 Getting Started With JAX-WS Web Services for Oracle WebLogic Server extends GenericServlet { ... private BackendServiceService _service; ... Client ID ClientIdentityFeature clientIdFeature = new ClientIdentityFeatureMyBackendServiceAsyncClient; features.addclientIdFeature; ... _features = features.toArraynew WebServiceFeature[features.size]; ... BackendService port = _service.getBackendServicePort_features; ... java.io.Closeable_port.close; } }

6.6.2 Accessing the Server-generated Client ID