This tutorial is purely on programming SOAP Web Services with JAVA. First of I will give a sample case study. Then I will implement the same. By reading this article, You can learn the implementation of SOAP web services with JAVA. You need to have Tomcat server configured Eclipse.

What is SOAP :

SOAP stands for Simple Object Access Protocol. We can send messages by using this Protocol. SOAP is based on XML, so it is independent of programming platform.
SOAP Message Syntax :
<?xml version="1.0"?>



SOAP Body contains message
SOAP Header contains data other than message (Authentication info, Login User ID...etc)
SOAP Fault contains reason for failure.

Case Study :

This project is for maintaining Employee information. We have to convert below Case Study into Web Service project. 
  1. Create Employee Class
  2. Create EmployeeService Class with methods createEmployee(String id, String name, String email), deleteEmployee(String id), selectEmployees()
  3. Create one global HashMap to maintain Employee Info.
  4. createEmployee is for creating employees, This method takes Employee object as input and returns String
  5. deleteEmployee is for deleting employees, This method takes Employee ID (String) as input and returns String
  6. selectEmployees is for reading all employee info. This method returns List of Employee details

Annotations :

@WebService Annotation

        portName = "EmployeePort",
        serviceName = "EmployeeService",
        targetNamespace = "",
        endpointInterface = ""
This annotation is for java class which works as Sevice
portName - specifies wsdl:port
serviceName - specifies Service Name
targetNamespace - specifies Namespace for WSDL
endpointInterface - java interface class which Service class implements

@WebMethod Annotation

This annotation is for method in service class which implements functionality
action - specifies SOAP action
operationName - specifies soap:operation
exclude - exclude the method from Web Service

@WebParam Annotation

This annotation is for defining request parameters. 
@WebParam(name = "i") int i

Setup Apache Axis2

Apache Axis 2 is Web Service engine which supports SOAP messages.

Axis2 Preferences

  1. Download the Axis 2 binary distribution (here)
  2. Extract it
  3. Enter Eclipse and go to Window > Preferences > Web Services > Axis2 Preferences
  4. In the Axis2 runtime location field, points to your Axis2 installation directory (the one you created in step 2)
  5. Click Apply
  6. Close Preferences and try again

Server and Runtime

  1. Enter Eclipse and go to Window > Preferences Web Services Server and Runtime
  2. In the Web Service runtime field, points to your Axis2 installation directory (the one you created in step 2)
  3. Click Apply
  4. Close Preferences and try again

Setup Chrome / Firefox  SOAP Web Service Testing Plugin

Install Wizdler in chrome. You can find this plugin here
Install SOA Client for Firefox. You can find this plugin here


Create New Dynamic Web Project SimpleSoapExample in Eclipse
Create java package
Create Employee Pojo Class

public class Employee {
    String id;
    String name;
    String email;
    public String getId() {
        return id;
    public void setId(String id) { = id;
    public String getName() {
        return name;
    public void setName(String name) { = name;
    public String getEmail() {
        return email;
    public void setEmail(String email) { = email;

Create EmployeeList Pojo class like below
Here I have used Employee Array because JAX-RPC doesn't support any collections. This class is for showing list of Employees

public class EmployeeList {
    private Employee[] employeeList;
    private int count;

    public Employee[] getEmployeeList() {
        return employeeList;

    public void setEmployeeList(Employee[] employeeList) {
        this.employeeList = employeeList;

    public int getCount() {
        return count;

    public void setCount(int count) {
        this.count = count;
Create below EmployeeService class in the package
This is Service class. We can access methods in this class through SOAP web service

import java.util.HashMap;
import java.util.Map.Entry;
import java.util.Set;
import javax.jws.WebMethod;
import javax.jws.WebParam;
import javax.jws.WebResult;
import javax.jws.WebService;

        portName = "EmployeePort",
        serviceName = "EmployeeService",
        targetNamespace = ""
public class EmployeeService {
    private static HashMap<String,Employee> empData = new HashMap<String,Employee>();

    @WebResult(targetNamespace = "")
    public String createEmp(@WebParam(name = "id") String id,@WebParam(name = "name") String name,@WebParam(name = "email") String email ) {
        Employee emp = new Employee();
        empData.put(emp.getId(), emp);
        return "success";
    @WebResult(targetNamespace = "")
    public String deleteEmp(String empID) {
        return "success";
    @WebResult(targetNamespace = "")
    public EmployeeList readEmp() {
        EmployeeList empListPojo = new EmployeeList();
        Set<Entry<String, Employee>> eset = empData.entrySet();
        int i=0;
        Employee[] empList = new Employee[empData.size()]; 
        for(Entry<String, Employee> en : eset) {
            empList[i] = en.getValue();
        return empListPojo;

Generate web service 

Right click on the project, click on New > Web Service. Make web service configuration as like below.
Click on Browse and select EmployeeService class
Then click Finish

Test the Service 

Add the project to tomcat and start the server. Open http://localhost:8080/SimpleSoapExample/services/EmployeeService?wsdl in chrome / firefox browser. Then you can see the SOAP Service testing plugin icon like below. 

Click on those links and test respective web services.

SOAP UI Eclipse Plugin 

Install plugin

Download SOAP UI Eclipse plugin from here.
Click on Help > Install New Software > Add
Enter "SOAP UI" in the name field.
Click on Archive.. and select downloaded eclipse plugin archive file

Create New SOAP UI Project

Click on Window > Open Perspective > Other > soapUI
Right click on Projects > New soapUI Project
Enter "http://localhost:8080/SimpleSoapExample/services/EmployeeService?wsdl" in the Initial WSDL/WADL
Click on OK

Test the web service

Now it will show all web methods to test (createEmployee, deleteEmployee, readEmployee).



Popular Posts