Friday, March 27, 2009

A simple webservice with Apache Axis

Download:ws-simple.war
Hi readers,
    There're many ways to depvelop a webservice. In this post, I want to introduce a way to build webservice with apache axis (http://ws.apache.org/axis/). I'm going to implement a very simple function: when receiving a request from client, server will reponse a string to client.
What should we need?
    IDE: Eclipse 3.4.
    Library: apache axis.
      +axis.jar
      +commons-discovery-0.2.jar
      +commons-logging.jar
      +jaxrpc.jar
      +saaj.jar
      +wsdl4j.jar
Steps:
1, Create a dynamic web project inside eclipse.
2, Add the librarise (as listed above) into the project, also add these to build path.
3, Write your codes.
4, Export war file (using eclipse or ant task).
5, Put war file into apache tomcat server (webapps directory)
6, Open browser and test (eg: http://localhost:8080/ws-simple/services/EchoService?wsdl)

The picture below is the structure of application.


Let look inside the application:
+User.java is a complex parameter of webservice.
+IEchoService.java is an interface in which there're three functions:
        public String echo(String message);
        public String addUser(User user) throws Exception;
        public String printback(String text);
+EchoServiceImpl.java: implemented class of the above interface.
+Declare Axis servlet in web.xml file.
+Expose the webservice by using server-config.wsdd file.
    -To create server-config.wsdd file we can use Java2WSDL tool inside apache axis library.

No comments:

Post a Comment