Interview Questions

Axis2 - Simple Web Service Example

In this section, let us see how to create a Simple Web Service using Axis-2 Web Services Engine.

Lets create a simple Java class which has only one operation "getName()".

SimpleWebService Class

package in.techdive.axis2.samples;

public class SimpleWebService
        public String getName(String p_name) throws Exception
                return p_name;

Create a XML file named services.xml file as follows,


<service name="SimpleWebService">
        Simple WebService Demo
    <parameter name="ServiceClass">in.techdive.axis2.samples.SimpleWebService</parameter>
    <operation name="getName">
                <messageReceiver  class="org.apache.axis2.rpc.receivers.RPCMessageReceiver" />


1. Create src directory inside the Project Home. Place the inside src\in\techdive\axis2\samples directory
2. Place the services.xml inside src\in\techdive\axis2\samples\META-INF directory.

Web Service Deployment:

Create an Axis archive(aar) file as SimpleWebService.aar. This file should contain the contents as below,



Place the SimpleWebService.aar file inside <AXIS2_HOME>/repository/services

Testing Web Service:

Now, its the time to test the deployed Web Service.

Start the Axis2 Server by running the <AXIS2_HOME>/bin/axis2server.bat. Once the server starts successfully, open the below the url in the browser.


This will display the WDSL content of the Service exposed. This means that the Service is deployed properly.

Download any open source SOAP UI Tool for testing our Web Service. Create the Request SOAP message and send it to the above URL. This SOAP Request will be received by the Axis engine and it will be sent to the SimpleWebService class for business logic processing and the Response SOAP message will be sent to the Client.

Request SOAP Message

<soap:Envelope xmlns:soap="" xmlns:sam="">

Response SOAP Message

<soapenv:Envelope xmlns:soapenv="">
      <ns:getNameResponse xmlns:ns="">

Once the SOAP Request is sent to the above URL, the method getName() in SimpleWebService class will get executed and returns the response in XML format.