Writing a simple web service and a client with Axis2

1. The service

Here a simple POJO service will be created. For simplicity the service will have only two operations.

1. Save an order which consists of an index(String) and a price(Double)
The order will be saved to an xml file.

2. Retrieve the price given the index.

First create a Java Project.

Now inside package I create the Order POJO.

Inside the package orderprocessing.service I create OrderProcessingService Class.

In order to save orders to an XML file I create
To retrieve orders from the XML file I create
Create an XML file orders.xml somewhere and change the "savePath", and "retrievePath" attributes inside the above two classes according to that.

Now create a folder META-INF at the src folder level and create services.xml inside META-INF.

Here, If you do not specify the message receiver, then the default message receiver which is RawXMLINOutMessageReceiver will perform the operation[1]

And since the service implementation class is in Java, all the public methods in that service will be exposed. No need to specifically include them in services.xml[1]

This is the folder structure of my service.

Now export the project as a jar. In eclipse this can be done by, right click on the project->export
Save it to somewhere and change it's extension to .aar (eg: if your jar is OrderProcessingService.jar rename it as OrderProcessingService.aar ) and save it to axis2-1.6.2/repository/services
(I am using axis2-1.6.2)

Start the axis2server. (In linux run inside axis2-1.6.2/bin)

Now if you go to http://localhost:8080/axis2/services/ it should be shown as below.

And you can access the wsdl at, http://localhost:8080/axis2/services/OrderProcessingService?wsdl

2. The client

Create another Java project.

Now in order to use the service we need to create the stub.

Go to axis2-1.6.2/bin in the terminal and run,
Now create another package orderprocessing.client inside your client project and create

This is my folder structure of the client

Run the client and see if it works.