Social Icons

Java SOAP Web Service (JAX-WS) using Eclipse

Today let's try out an example on how to create a Java SOAP based Web Service also known as JAX-WS using Eclipse. We will build a web service that will accept an Employee Salary object or POJO (EmpSal) which contains Basic Salary & Variable Salary components and add those and set the result as CTC and return back the EmpSal object to the client.

Developed with:
  • JBoss 6
  • Apache commons codec jar (For Base64 encoding)
  • Eclipse Juno
Create Java Project in Eclipse (This will be our web service provider)
First create the EmpSal class, which we will actually use to transfer from client to service and back:

Next, create the interface for the webservice which defines the blue print of the service:

Create the web service class which implements the interface with the underlying Business logic. Note that this example implements Base64 Basic decoding, thus the web service client is expected to pass the authentication to be able to get a valid response from the web service.

Now, Create a Dynamic Web project in Eclipse
Add the following configurations in the web.xml of the project

Add the Java project created in the beginning to the Dynamic Web project as follows: Project Properties -> Deployment Assembly -> Add

Deploy the Dynamic Web Project on JBoss and hit the following URL on your browser for the WSDL of your Web service you have just created:

You should be able to see the WSDL of your web service, and we will use the same to create a SOAP client to talk to our newly created web service.

Finally, Create a Web Service Client project in Eclipse
Create a New "Web Service Client" project in eclipse and provide the WSDL url as shown above. Provide a client project name and set the the client project type as "Java Utility Project" which basically means a standalone Java program.

The above steps will automatically create Interfaces and Implementations of the Web Service and Web Service Proxy also the Service Locator and Soap Binding Stub class along with the Employee class.

You would require to add a class with main() for calling the web service as follows:

Now start the Dynamic Web Project as you deploy it on JBoss, and execute the Client code, The client will send and employee object wrapped in SOAP envelope to the Web service and in return receive the same object back with CTC calculated and set in the employee object.

Download WebService Client Project
Download WebService Project


  1. Getting below erreor while running the client.please help....

    faultCode: {}Server
    faultString: org/apache/commons/codec/binary/Base64
    at org.apache.axis.message.SOAPFaultBuilder.createFault(
    at org.apache.axis.message.SOAPFaultBuilder.endElement(
    at org.apache.axis.encoding.DeserializationContext.endElement(
    at Source)
    at Source)
    at$ Source)
    at Source)
    at Source)
    at Source)
    at Source)
    at Source)
    at Source)
    at Source)
    at$JAXPSAXParser.parse(Unknown Source)
    at javax.xml.parsers.SAXParser.parse(Unknown Source)
    at org.apache.axis.encoding.DeserializationContext.parse(
    at org.apache.axis.SOAPPart.getAsSOAPEnvelope(
    at org.apache.axis.Message.getSOAPEnvelope(
    at org.apache.axis.handlers.soap.MustUnderstandChecker.invoke(
    at org.apache.axis.client.AxisClient.invoke(
    at org.apache.axis.client.Call.invokeEngine(
    at org.apache.axis.client.Call.invoke(
    at org.apache.axis.client.Call.invoke(
    at org.apache.axis.client.Call.invoke(
    at org.apache.axis.client.Call.invoke(
    at com.egi.demo.webservice.CalcCTCWebServiceImplServiceSoapBindingStub.calcCTC(
    at com.egi.demo.webservice.WSClient.main(


  2. I want soap web-service example program with screen-shots, can anyone help..

  3. Man you save me! I was trying to learn how to pass username and password in my java cliente and i founded you article and you save, although I dont' understand you it Works, but it Works... Thank you!!!!

  4. i want soap web services which allow user to review, edit or delete review