03 - JAX WS Creating Web Service Client

3.1 Need for Web Service Client

We need to use Web Service Client to consume the service and use the data in the presentation layer

3.2 There are two types of client APIs are available in JAX WS as below:

i. Dispatch client API:

By using this client, generating JAVA artifacts are not required and we can work on XML message itself

This API is based on  javax.xml.ws.Dispatch interface which is a dynamic programming interface

Data can be sent either in Message or PAYLOAD mode

When message mode is used, the entire SOAP message, including envelop, header and body are processed

In case of PAYLOAD mode, contents of SOAP:BODY alone will be processed

The following types of objects are supported by this client:
SOAP Message

There are three ways to invoke Dispatch Client

a. Synchronous invocation

b. Asynchronous

c. One way  invocations

ii. Dynamic client-API: This API is used to generate JAVA artifacts from a WSDL file

  and this is called static programming model

3.3 Asynchronous Web Services Invocation:

JAX WS Supports Asynchronous Web service Invocation by both Callback and Polling model. Both the clients can invoke web service asynchronously

Send the request to SEI and returns response immediately

In Polling model, receives a response polled to determine whether the server has responded

In callback model, callback handler to accept and respond  and continuing process the work

3.4 Steps to create a Web Service Client using Eclipse:

  • Create a dynamic web application project
  • Place the wsdl file in the web - INF folder
  • Right click on wsdl file and generate Web Service client

Fig - Creating a Web Service Client using Eclipse

3.5 Implementation with Examples

While click on Generate client  as shown in fig 3-1 will create auto generated classes inside WebService Client project as below:

The generated proxy class contains the methods which we will invoke from the client

In our example CustomerInfoProxy class contains the method addCustomer with its default implementation as below:

 public org.example.www.customerInfo.AddCustomerResponse addCustomer(org.example.www.customerInfo.AddCustomerRequest parameters) throws java.rmi.RemoteException{
    if (customerInfo_PortType == null)
    return customerInfo_PortType.addCustomer(parameters);

The generated classes for web service client is shown in fig 3-2

          Fig - The generated classes for web service client

In this proxy class, we are initializing the service endpoint address and the service port in initializing method and use those objects to call the web service methods

We can create instance of the proxy class in the presentation layer classes to access the data consumed from the webService Client.

Like us on Facebook