Create Java SOAP Web Service Using Eclipse

In this tutorial I will teach you the simplest way to create Java SOAP web service using Eclipse IDE.

I have created this example using Eclipse Kepler. I am sure it will work with any other Eclipse version. But make sure your IDE contains Apache Tomcat and Apache Axis.

Apache Axis will do the work of creating web service using Java source file and Apache Tomcat server will be used to run and test the web service.

So without wasting any time lets begin the process.

Create Java SOAP Web Service Using Eclipse

Create Java SOAP Web Service Using Eclipse

1. First of all open Eclipse and go to File > New > Dynamic Web Project

AJAX with JSP Using jQuery Example

 

2. Give a project name and then click on Finish button to create a dynamic web project.

Create Java SOAP Web Service Using Eclipse 1

 

3. Now create a Java class inside src folder in com package. You can choose the package and class name according to you.

Create Java SOAP Web Service Using Eclipse 2

Create Java SOAP Web Service Using Eclipse 3

 

4. For demonstration purpose I am creating a function in our class that will take two numbers and return sum of these two numbers. Add following code in your class. You can create more functions according to your requirement.

package com;

public class DemoClass {
	public String func(int a,int b){
		return String.valueOf(a+b);
	}
}

 

5. Right click on Java class and go to Web Services > Create Web Service.

Create Java SOAP Web Service Using Eclipse 4

 

6. Select all the settings as given in below screenshot. Finally click on Finish button to create the web service.

Create Java SOAP Web Service Using Eclipse 5

 

7. After the web service is created a browser will be opened. Here we have to test our web service is working properly or not.

Create Java SOAP Web Service Using Eclipse 6

 

8. Under Methods you can see all the methods that we have in our class. In this case we have only one method func(). Click on it, now enter values of arguments a and b in the text boxes provided. Finally click on Invoke button to invoke the method. You can see the result of the method under Result.

Create Java SOAP Web Service Using Eclipse 7

 

9. A WSDL file is created in SOAP web service. It contains all the details of the web service. Like name of methods, name of arguments, return type, etc. You can see the WSDL file by going to folder WebContent > wsdl.

Create Java SOAP Web Service Using Eclipse 8

 

10. In our case the WSDL file will look like this.

<?xml version="1.0" encoding="UTF-8"?>
<wsdl:definitions targetNamespace="http://com" xmlns:apachesoap="http://xml.apache.org/xml-soap" xmlns:impl="http://com" xmlns:intf="http://com" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:wsdlsoap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<!--WSDL created by Apache Axis version: 1.4
Built on Apr 22, 2006 (06:55:48 PDT)-->
 <wsdl:types>
  <schema elementFormDefault="qualified" targetNamespace="http://com" xmlns="http://www.w3.org/2001/XMLSchema">
   <element name="func">
    <complexType>
     <sequence>
      <element name="a" type="xsd:int"/>
      <element name="b" type="xsd:int"/>
     </sequence>
    </complexType>
   </element>
   <element name="funcResponse">
    <complexType>
     <sequence>
      <element name="funcReturn" type="xsd:string"/>
     </sequence>
    </complexType>
   </element>
  </schema>
 </wsdl:types>

   <wsdl:message name="funcRequest">

      <wsdl:part element="impl:func" name="parameters">

      </wsdl:part>

   </wsdl:message>

   <wsdl:message name="funcResponse">

      <wsdl:part element="impl:funcResponse" name="parameters">

      </wsdl:part>

   </wsdl:message>

   <wsdl:portType name="DemoClass">

      <wsdl:operation name="func">

         <wsdl:input message="impl:funcRequest" name="funcRequest">

       </wsdl:input>

         <wsdl:output message="impl:funcResponse" name="funcResponse">

       </wsdl:output>

      </wsdl:operation>

   </wsdl:portType>

   <wsdl:binding name="DemoClassSoapBinding" type="impl:DemoClass">

      <wsdlsoap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>

      <wsdl:operation name="func">

         <wsdlsoap:operation soapAction=""/>

         <wsdl:input name="funcRequest">

            <wsdlsoap:body use="literal"/>

         </wsdl:input>

         <wsdl:output name="funcResponse">

            <wsdlsoap:body use="literal"/>

         </wsdl:output>

      </wsdl:operation>

   </wsdl:binding>

   <wsdl:service name="DemoClassService">

      <wsdl:port binding="impl:DemoClassSoapBinding" name="DemoClass">

         <wsdlsoap:address location="http://localhost:8080/SOAPExample/services/DemoClass"/>

      </wsdl:port>

   </wsdl:service>

</wsdl:definitions>

 

Watch Video Tutorial

So, this was the simplest way to create Java SOAP web service using eclipse. Comment below if you are facing any problem. I will try my best to help you.

4 thoughts on “Create Java SOAP Web Service Using Eclipse”

  1. This page worked very well for me! I’m looking at my first SOAP web service. Now on to the REST demo. Well done!

Leave a Comment

Your email address will not be published. Required fields are marked *