Cristiano Novelli

TUTORIAL: Create a Web Service with Axis2

This tutorial is based on the Axis2 Quick Start Guide.
It is required you have installed Axis2 on Apache Tomcat.

To Create a Web Service we will use a Template Eclipse Project and the tasks defined in an ANT build file.
In this document we start from an initial template project and we describe how create a web service and related client (packaged into the final template project). See to the end of this page to download the packages.

Save, extract and import the initial template project in Eclipse.

Configure in your eclipse project:
- Source Dir: Axis2_Template\build\service\src
- Output Dir: Axis2_Template\build\classes

The project contains:
- a Java class,;
- an ANT file, build.xml, that allow to design quickly and easily our web service through theese tasks:
0.1.clean.service *
0.2.init.service *
0.3.compile.service **
[* tasks 0.1 and 0.2 are disenable beacause are dangerous,
they can to delete java classes modified in the successive tasks]
[** task 0.3 is not necessary if you have configurated Eclipse project as told above]

Modify the CONFIGURATION section of ANT file build.xml.
It's important, above all, this line:
<property name="" value="TemplateService"/>

The TemplateService java class is the representation of target web service, the POJO.
If you will create your web service you have to modify this starting class.
This POJO contains a string only and two methods, getString and setString to read and write this text variable.

Let's start!

- 1.generate.wsdl
This first task generates the WSDL file TemplateService.wsdl from java class.

- 2.generate.service
This task generates the service structure from WSDL.
Refresh your Eclipse Project, you can see a new package:
that contains the Skeleton file, core of our web service.

- Modify the Skeleton
Open and modified it as into the section "Generating the Service using ADB" of the Axis2 Quick Start Guide. You can see the final result in the our final template project.
N.B. Eventually, in the case of Complex Type,
Import the pojo.xsd.* package and NOT the pojo.* package , at this point may be a facile error;

- 3.deploy.service
This task creates the .aar (Axis Archive) and copy it into the services directory of Axis on Tomcat.
You will see into the Tomcat shell something like this:
[INFO] Deploying Web service: TemplateService.aar - file:/C:/Java/Tomcat 5.5/webapps/axis2/WEB-INF/services/TemplateService.aar
The web service is ready! You can test your work with some calls:
to view the WSDL of the service;
(to check the ws working. N.B. refresh your browser if you don't see differences between the two getString).

- 4.generate.client
This task generate the Stub for your client.
Refresh your Eclipse project, into the build/client/ folder you will see the java source created.
Add the build/client/src to the source folders on buil path
( Project > Properties > Source > Add Folder... ).

- Create Client
in build/client/src folder create: with main method.
Now you have to implement the web service client calls for getString and setString and call them using the Stub. N.B. It is important to specify correct service for the stub:
TemplateServiceStub stub = new TemplateServiceStub("http://localhost:8080/axis2/services/TemplateService");
You can see the section " Generating a Client using ADB" of the Axis2 Quick Start Guide and to find the final result in the our final template project.
Import the pojo.xsd.* package and NOT the pojo.* package , at this point may be a facile error;

This task creates the .jar for the client and copy it into the build/client/build/lib/ folder.
Then the task launch ADBClient.
You will see into the Eclipse shell something like this:

[jar] Building jar: C:\Java\workspace-ganymede\Axis2_Template\build\client\build\lib\TemplateService-test-client.jar
[java] First getString call: ciao
[java] Second getString call: Hello Service Template!

Your client call the service and print the results!
With this template package you can create axis2 web services renaming where it occours.

- Download
initial_Axis2_Template .zip


CP-NET Project
- X-Lab Libraries
- Tutorials
- Links