Steps for creating webservice client using RAD

In the previous article we have seen how to create server side component of webservice using RAD. Now we need to create a web service client and call the service from the client. Below are the steps to follow to create the client to access the web service:

  • Create a Project for the Client in the same workspace. Give the project name as DemoWebServiceClient (or any name of your choice).
  • Create the client stubs from the wsdl file of the web service provider.
  • Write a sample program in client to access the web service through the client stubs which were created.

Create the Client Project

To create a new client project perform the below navigation:

Right click on the Dynamic Web Project ->click on New -> click on Dynamic Web Project. Give the Project name as DemoWebServiceClient. All the values give as default as it is.

Next click on the Finish button. Now a new project added to your current workspace with name DemoWebServiceClient. The client EAR will be DemoWebServiceClientEAR.

Generate the Client Stubs from the WSDL file

Following are steps for how to create the client stubs from the wsdl file of the web service provider.

Go to the DemoWebService project wsdl file. The wsdl file will present in the WebContent\WEB-INF\wsdl\CalculatorService.wsdl folder.

Right click on wsdl file ->click on Web Services -> click on Generate Client.




RAD Interface

The forthcoming screenshots will provide the steps to how to create the client stubs from the web service wsdl file.




This screen will ask for client proxy type. Choose the default proxy type which is Java proxy. Now click on Next.





In the above screen enter the path of the wsdl file. The client stubs will be generated based on the wsdl file. Here in wsdl URI will be pre filled with the wsdl file location path. If you want to select an external wsdl file then browse and select the wsdl file. Now click on Next.



This screen will ask for the Client type, Client Project Name & Client EAR project where all the client stubs will be generated. Now in this case our client type is default which is Web, Client project is DemoWebServiceClient and the Client EAR is DemoWebServiceClientEAR. If you want to change the client server version then through the EDIT button you can change. Now click on Next.







This screen is for security setting in web service client. But here noting to change and click on Finish.



Project Explorer

Below client stubs files will be created in the Client EAR for accessing the remote web service. The Client stubs are:

1. CalculatorService.java
2. CalculatorServiceProxy. java
3. CalculatorServiceService.java
4. CalculatorServiceServiceInformation.java
5. CalculatorServiceServiceLocator.java
6. CalculatorServiceSoapBindingStub.java

The CalculatorService.java is the remote interface which contains all the abstract methods of the web service.

The CalculatorServiceServiceLocator.java will contain the address of the remote server where the web service is deployed.

Access the web service from the client

Write a sample web service client program to access the service. Below is the client program which is accessing the remote web service.

Client Program Description

To get the address of the remote web service deployed server you need to create the object of CalculatorServiceServiceLocator class. Through the getCalculatorService() method of CalculatorServiceServiceLocator will get the reference of the CalculatorService (Remote Interface). Now invoke the service methods on CalculatorService which internally invoke the actual service method and give the results. Here the CalculatorServiceSoapBindingStub class contains the XML parsing implementation between the java and xml data type conversion. The client will communicate through SOAP over HTTP with the remote web service deployed server. The client stubs contains the JAX-RPC implementation for platform independent communication.



Execute the Client Application

Find the below navigation to execute the client application in RAD.

Navigation: Right click on DemoServiceClient.java -> click on Run -> Click on Java Application.



Check the results in the Console window of RAD.

No comments:

Post a Comment