Thursday, November 20, 2014

Create Web service client with using Axis2 in Eclipse

Create web service client with using Axis2 in eclipse

Web service helps to communicate the different application with out consuming more time even the applications are deployed in different platform. The reason behind was, the all communication is in XML. In previous tutorials briefly explain that how to create the WSDL and How to write the web service and deploy to the server and test. 

In this tutorial you able to learn that, to build the client with using the WSDL generated here

Objective : Create a web service client with using the Axis2 in eclipse.

Scope : Create we web service client with using the Axis2 and test the client service.

Requirements : 
  • Ecipse Java EE IDE
  • Axis2 - 1.6.2
  • Apache tomcat 6.0.26
Step 1 : Create a Dynamic web project  with using eclipse and name it as "ServiceClient". Right click on the "ServiceClient" project and create a web service client with using eclipse. 

The way of creating the web service client in eclipse mentioned as below. 

       New > Other > Web Service > Web Service Client


Step 2 : Chose the WSDL, which we created in the previous article. In additionally in the client generation wizard, select the Axis2 as web service run time and Tomcat 6 as a server. Click the next button to continue the wizard process.




Step 3 : Click the next button with out changing any of the parameters and finally click the finish button. Once you pressed the finish button, the auto generated code will added to the  "ServiceClient" project. (The auto generated classes are HelloworldCallbackHandler .java and HelloworldStub.java


Step 4 : In order to test the generated client, you have to write a separate class in java. In our example in order to test the client, you able to use the following "TestClient" class.

/ServiceClient/src/findanidea/webservice/services/helloworld/TestClient.java


 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
package findanidea.webservice.services.helloworld;

import java.rmi.RemoteException;

import findanidea.webservice.services.helloworld.HelloworldStub;
import findanidea.webservice.services.helloworld.HelloworldStub.SayHello;


public class TestClient {
 public static void main(String[] args) throws RemoteException {
  HelloworldStub stub = new HelloworldStub();
  SayHello sayHello = new SayHello();
  sayHello.setName("John");
  System.out.println(stub.sayHello(sayHello).getOutput());
 }
}


Once you execute the above mentioned "TestClient" class, you able to retrieve the "Hello... John" message in application console.



Hope its helps.... 

No comments:

Post a Comment