Monday, 4 April 2016

How to create web service (server) using Axis 2 and eclipse ?



A. Configure Axis 2 in eclipse

Configure Axis 2 Runtime
1. Go to Windows - Preferences - Web services - Axis2 Preferences
2. Browse the location of Axis 2 API folder (for ex. axis2-1.4.1) in section Axis2 Runtime
3. Check if the Axis2 runtime loaded successfully.
4. Click Apply and OK.

Configure web server
1. Go to Windows - Preferences - Server - Installed Runtimes
2. Click Add and choose server (for ex. Tomcat 5.5)
3. Browse the location of folder where server installed (for ex. apache-tomcat-5.5.25)
4. Configure installed JREs and select JRE to use.
5. Click Finish and OK.

Configure server and runtime for Web service
1. Go to Windows - Preferences - Web services - Server and Runtime
2. Select server (for ex. Tomcat 5x)
3. Select Web service Runtime (for ex. Apache Axis 2)
4. Click Apply and OK.



B. Generate skeleton code and implement WS methods

1. Create a new web project
2. Create a folder named "wsdl" in the web application and put your WSDL inside it.
3. Right click on WSDL file and choose Web services - Generate java bean skeleton
4. Check the configuration -
     Server (for ex. Tomcat 5x)
     Web service runtime (for ex. Apache Axis 2)
5. Click Next - Next and at last, on start service page, click cancel.
6. Check if the skeleton Java code is auto-generated.
7. Check and open the generated skeleton java class. (for ex. Hello_ServiceSkeleton.java)
8. Check the required operation(s) under skeleton java class. (for ex. sayHello method)
9. Implement the operation(s) as per the business and return the proper response.
    Note: By default All the operations in skeleton class will have implementation to throw an exception.


C. Check the service deployment

1. Start the server and check your web application using its URL : 
     http://localhost:8080/HelloServer
2. Check the presence of the link services and click on it.
3. Check the presence of your web service and click to check the deployed WSDL.
     It will open the WSDL URL, 
     For ex. -  http://localhost:8080/HelloServer/services/Hello_Service?wsdl

Your web service will be accessible using the endpoint URL :  
http://localhost:8080/HelloServer/services/Hello_Service

No comments:

Post a Comment

Note: only a member of this blog may post a comment.