SOAP(Simple Object Access Protocol) is one of the popular way of inter application communication, application can be on different system or same system using network, can on different languages. SOAP can work with many protocol such http, SMTP etc. SOAP has two flavour RPC Style and Document based. SOAP has strict contract defined in form of WSDL. You can start creating Java class and later define WSDL based on class(bottom up approach) or define WSDL and generate Java class(top down approach). Defining WSDL can be tedious sometime for complex services so top down can be tedious compared bottom up approach.

What is WSDL.

WSDL is contract definition written in form of single XML. It contains message type of request and response, endpoints etc. Here is the detailed list of WSDL component.

<definitions name = "EmployeeService"
   targetNamespace = ""
   xmlns = ""
   xmlns:soap = ""
   xmlns:tns = ""
   xmlns:xsd = "">
      to define complex types if there are any........
   <message name = "GetEmployeeRequest">
      <part name = "id" type = "xsd:string"/>
   <message name = "GetEmployeeResponse">
      <part name = "name" type = "xsd:string"/>

   <portType name = "Employee_PortType">
      <operation name = "getEmployee">
         <input message = "tns:GetEmployeeRequest"/>
         <output message = "tns:GetEmployeeResponse"/>

   <binding name = "Employee_Binding" type = "tns:Employee_PortType">
      <soap:binding style = "rpc"
         transport = ""/>
      <operation name = "getEmployee">
         <soap:operation soapAction = "getEmployee"/>
               encodingStyle = ""
               namespace = "urn:examples:employeeservice"
               use = "encoded"/>
               encodingStyle = ""
               namespace = "urn:examples:employeeservice"
               use = "encoded"/>

   <service name = "EmployeeService">
      <documentation>WSDL File for EmployeeService</documentation>
      <port binding = "tns:Employee_Binding" name = "Employee_Port">
            location = "" />

RPC vs Document Based.

These two are type of message formate. Document based is full fledged complex message which can have multiple for itself while RPC is straight forward input output parameter for a method. You can say Document follows Object based approach and easy to map to and from a Java object while, RPC based is just a simple input output parameter based on that specific method.

Top down approach.

Java command line tool

Java provides a small tool to generate Java classes based on defined WSDL. It can create a server side classes as well as client side also. wsimport -s . -p employeeservice.wsdl
It will creates three classes, and

  name = "EmployeeService", 
  targetNamespace = "******")
@SOAPBinding(style=Style.RPC, use=Use.ENCODED)
public interface EmployeeService {
      action = "*******"
      + "EmployeeService/getEmployee")
      name = "GetEmployeeResponse", 
      targetNamespace = "********", 
      partName = "name")
    public String getEmployee(int id);

public interface EmployeeServiceImpl implements  EmployeeService{
    public String getEmployee(int id){
      return employeeRepo.get(id);

Eclipse Web service generator .

Even eclipse provide support to create the classes automatically based on WSDL. eclipse

Bottom up Approach

In bottom up we create a class with some methods and then create service out of it.

Java approach.

Use @WebService, @WebMethod and @WebResult annotation to annotate the class and methods. It will somewhat same as generated class file from java or eclipse tool. Once you publish the service wsdl will be available on the URL.

Eclipse approach.

Create a simple bean with methods which needs to be expose. Then in eclipse select bottom up approach and select the bean. It will create helper classes and WSDL automatically. eclipse

Creating client.

Eclipse tool - In both the top down and bottom up approach you have option to create client as well. It creats separate project and creates client classes. Java command line tool - Use following class to create client classes automatically. wsimport -keep -p http://localhost/employeeService?wsdl

public class EmployeeServiceClient {
    public static void main(String[] args) throws Exception {
        URL url = new URL("http://localhost/employeeService?wsdl");
        EmployeeService employeeService 
          = new EmployeeService(url);
        EmployeeService employeeServiceProxy 
          = employeeService.getEmployeeServiceImplPort();
        String name 
          = employeeServiceProxy.getEmployees(1);

Publishing WebService

In the end you would need to publish the web service and make it available.

           new EmployeeServiceImpl());