Soap Web Service – Introduction

Last modified on September 7th, 2014 by Joe.

This article is to help us understand what is a soap web service. Through this tutorial, we will learn to create a simple hello world web service and a web service client to consume it, of course all in java.

All my beginner friends, go choose your weapon. I repeat, programmer without an IDE is zorro without a sword! I have chosen Eclipse as my IDE, there are numerous free IDE available. You may choose Eclipse or Netbeans. After choosing the IDE your next priority is to learn the IDE (Eclipse) shortcuts.

For this article to create a hello world soap webservice, I have chosen Netbeans as the IDE. Netbeans provides better out of the box support for web service development.

Soap webservice is cumbersome to work with in comparison to RESTful web services. If the soap web service development is going to happen using notepad then that is the first dumbest big mistake in the development plan.

What is a web service?

W3C defintion for a web service is, “a software system designed to support interoperable machine-to-machine interaction over a network”.

Web service is an interface for your software. We may have web user interface or a thick client (desktop) user interface for our software. Imagine web service as another similar interface. This interface is not for humans but for softwares.

Web/thick client directly serves end user as an interface to interact with the software. Web service serves as an interface to software developers. Using web service as an API, developers can build external systems that will interact with the software.

There are two major categories of web services

  1. SOAP Web Service
  2. RESTful Web Service

Soap Web Service

Simple Object Access Protocol (SOAP) is a standard protocol specification for message exchange based on XML. Communication between the web service and client happens using XML messages. SOAP defines the rules for communication like what are all the tags that should be used in XML and their meaning.

RESTful Web Service

RESTful web service uses architectures that use HTTP or similar protocols by restricting the interface to use standard operations like GET, POST, PUT, DELETE for HTTP. Based on my experience RESTful is easier to develop. I know this statement will invite wrath of SOAP lovers.


One major component of a web service is Web Services Description Language (WSDL). It is an xml file that describes the web service technically in a machine readable format. That is, using this WSDL file we can understand things like,

I just want this article to be a beginning point for your web service exploration. Do not stop with this, explore more and more and you will love this service oriented architecture. Theory is too dull isn’t it? Lets move to fun part the coding.

Hello World SOAP Web Service

Download the latest Netbeans IDE. Go! I will wait… I am using NetBeans IDE 7.1 for this tutorial. You can download the complete source – SOAPHelloWorld of this article.

A Basic Web Application

File – New Project (Ctrl + Shift + n)
In ‘Categories:’ choose “Java Web”, in ‘Projects:’ choose “Web Application” and click Next.

In ‘Project Name:’ type “SOAPHelloWorld” and click Next.
By default ‘Server:’ is “GlassFish Server 3.1.1” and ‘Java EE Version:’ is “Java EE 6 Web” and click Finish.

Now you have created a basic web application. By default NetBeans creates web.xml and a welcome page (Hello World) jsp page.

Just to ensure our basic setup is good, right click on the project name and click ‘Run’.

(If you have firewall running, it may popup to allow access – just allow access)

We should get “Hello World!” message in the browser. This is just a basic web application printing hello world. Now we want to do the same thing using a web service.

Towards Web Service

Right click on project name, select ‘New’ and then select ‘Web Service’

Type ‘Web Service Name:’ as “HelloWorld”, then type ‘Package:’ as “com.javapapers.webservice” and click Finish.

Thats it! Web service development is done! Oh my God this is too much. Is that so easy?? Till now, we have heard a lot about web services but we never thought of it to be so easy! Wait wait, before we relax..

NetBeans has created this SOAP based hello world web service. Lets understand what it has done in the background and verify if it is working.

Service Code

Following is the java code that serves as the web service and it is generated by Netbeans.

 * To change this template, choose Tools | Templates
 * and open the template in the editor.
package com.javapapers.webservice;

import javax.jws.WebService;
import javax.jws.WebMethod;
import javax.jws.WebParam;

 * @author USER
@WebService(serviceName = "HelloWorld")
public class HelloWorld {

     * This is a sample web service operation
    @WebMethod(operationName = "hello")
    public String hello(@WebParam(name = "name") String txt) {
        return "Hello " + txt + " !";

hello is the operation that returns “Hello” + the parameter sent as argument.

WSDL of Web Service

Now right click the project and click run. Then type the following url in the browser


it will return the wsdl of the soap web service that we have created now. This wsdl contains,

Web Service Client

Now lets invoke this webservice and see how it works.
Open the index.jsp that was generated by NetBeans

Remove the “Hello World!” string. We are going to access the now created soap web service in the place and print whatever the web service returns.

Right click on the project and choose ‘New’ then ‘Web Service Client…’

In the New Web Service Client dialog select ‘WSDL URL:’ and type the wsdl url in the text box ‘http://localhost:8080/SOAPHelloWorld/HelloWorld?wsdl’. Then in package, type com.javapapers.webserviceclient and click Finish.

Invoke the Web Service

Now the web service client is ready. We need to invoke the hello world soap web service using the web service client we have created now.

In that place right click choose “Web Service Client Resources” then select “Call Web Service Operation…”

From that dialog select “hello” and clik ok. This is the operation we are invoking of that web service.

Following is the code snippet inserted by Netbeans IDE to access the web service.

    <%     try { 	com.javapapers.webserviceclient.HelloWorld_Service service = new com.javapapers.webserviceclient.HelloWorld_Service(); 	com.javapapers.webserviceclient.HelloWorld port = service.getHelloWorldPort(); 	 // TODO initialize WS operation arguments here 	java.lang.String name = ""; 	// TODO process result here 	java.lang.String result = port.hello(name); 	out.println("Result = "+result);     } catch (Exception ex) { 	// TODO handle custom exceptions here     }     %>

In the above code snippet, for vaiable ‘name’ assign a string value you prefer like,

java.lang.String name = "javapapers";

Right click the project and select ‘run’ and you get “Result = Hello javapapers ! ”

You can download the complete source – SOAPHelloWorld of this article.

Comments on "Soap Web Service – Introduction"

  1. sudharsan says:

    super ….

  2. manjit kumar says:

    hello sir,
    whenever i installed the eclipse i will give
    error “Failed to load JNI Shared Library ”

    Please tell me

  3. kamilo cervantes says:

    hello there,
    i hope you make a paper about jax-ws and BPEL :D

  4. demostene says:

    “I have chosen Eclipse as my IDE” and then you use NetBeans.

  5. shan says:

    HI we need same examle in eclipse IDE, Can you provide in eclipse?

  6. Anonymous says:


    Its really good and simple example to start with for WS beginners.


  7. ismail shepl says:

    really thank you so much for this cute and simple article.

    hope god help you in your life.


    dear ‘manjit kumar’,
    about your error “Failed to load JNI Shared Library ”
    just configure your eclipse.ini
    just correct the paths in it

    thank you again ENg.Joseph Kulandai


  8. anbalagan says:

    There was a Contradiction between two of your statements in article as below

    1.web service as another similar interface. This interface is not for humans
    2.Web service serves as an interface to software developers.

    Please describe

  9. Joe says:

    Let me clarify the interface statement. Web services are not an interface for end users, it is meant to be used by software developers. They will write another application which will connect with the web service.

  10. GeekDude says:

    This seems very clear. Good explanation Joe..Thank you very much.

  11. Anonymous says:

    please explore more. like How service is build and defining XSD with WSDL example.

    Navaz. shaik

  12. Padmanabhan says:


  13. Niket Patel says:

    would u please help me for attachment with axis1.4 ?
    i want to send a file using web-service to client when client call to service.
    i did it but i cant understand how file attached with handler.

    MessageContext msgContext = MessageContext.getCurrentContext();

    Message rspmsg = msgContext.getResponseMessage();

    DataHandler dhSource = new DataHandler(new FileDataSource(“c:\odbill.pdf”));

  14. Anonymous says:


    Great article.!

    can you please explain, writing web service (SOAP) without IDE too!

  15. Latha says:

    Can you provide me one example of complex data types for web services?
    where the service should use list of objects. Like returns array of objects.

  16. gopi says:

    Thanks alot Joe

  17. debashisparida parida says:

    sir can you help me how to use cvs tools
    in myeclipse..
    debasish on 13th 2012 6.40 pm

  18. Raghu says:

    I have generated the stub code using Axis2 (1.6.1) library to invoke a webservice. When i invoke a particular service, it is throwing below error

    org.apache.axis2.AxisFault: There was an exception running the extensions specified in the config file. —> Value cannot be null.
    Parameter name: input
    at org.apache.axis2.util.Utils.getInboundFaultFromMessageContext(
    at org.apache.axis2.description.OutInAxisOperationClient.handleResponse(
    at org.apache.axis2.description.OutInAxisOperationClient.send(
    at org.apache.axis2.description.OutInAxisOperationClient.executeImpl(
    at org.apache.axis2.client.OperationClient.execute(

    This service works fine with Axis1 and SOAPUI tool but not with Axis2. Can anybody please help me in this?

    Thanks in advance,

  19. sivaram says:

    Hi joe,

    this is sivaram . i am new to webservices

    can u give me a simple example to learn the webservice in eclipse.

  20. Raghu says:

    Simply Superb

  21. Amar says:

    I am using Apche CXF 2.5 to create soap web services.can i return List of ustom object from soap web service class

    Appreciate of your kind co-operation


  22. Anonymous says:


    Your i have one question.
    Soap based services generate xml to communicate.
    What about Restful services..

  23. s@nk@r says:

    This is very useful for me….
    we need example using myeclipse

  24. Anonymous says:

    Thanks Joe

  25. Luther says:

    Hi Joe,

    When I call the webservice operation I get an exception lang.NoClassDefFoundError .
    THere is some problem with the classpath I guess , kindly help

  26. Anonymous says:

    I like it so much… what a gr8 stuff to learn… i really appriciate this.

  27. Jasmine says:

    Could you kindly explain the differences between JMS and Web Service and when the JMS and Web Service will be used?

  28. Anonymous says:

    hi mr joe my apache tomcat is not creating cache

  29. vinu says:

    Hi Sir
    Using handlers i have intercepted my SOAP Response for attaching my hash i want to send this SOAP response to client.

  30. […] than passing information, we can generate code using these annotations. Take webservices where we need to adhere by the service interface contract. The skeleton can be generated using […]

  31. Java StAX says:

    […] scenario for putting best use of StAX are parsing WSDL in web services, viewing relational database data stored as XML documents and in general parsing predictable […]

  32. Praveen says:


    Its very much understandable.

    But I need this thing in Eclipse. And I’m working with th OS Ubuntu.


  33. Gopi says:

    Hi joe ,

    I learned a lot from your articles. Can you please post an article regarding webservices security and restful webservices in detail.

  34. Amir Iqbal says:

    Joe, You rock! Thumbs up for you !

  35. karthick says:

    Joe You are rock! can you give some more examples?

  36. shiva says:

    in wsdl file what is uses of minOccurs=”0″ and maxOccurs=”ünbounded” ?

  37. Anonymous says:

    I am fresher.
    I facing so much problem while learning SOAP.This site is really usfull for me..


  38. Anonymous says:

    Very Helpful information..above all a very excellent way of presenting the information.
    Keep up the good work…all the best cheers..:)

  39. Deep says:

    Nice article. Can you also post one for Rest WS.

  40. Janhavee says:

    hey joe,
    I am a frequent reader of ur articles. Find them very helpful for understanding of various java concepts.
    Now i have to start working on webservices.
    can you please add some more articles explaining webservices in a bit more detail. It will be great help.


  41. Anonymous says:

    NICE tutorial

  42. srinivas says:

    Can you please suggest any books on the webservices. I am novice to Webservices. Want to know more about it.

  43. Anonymous says:

    Nice, could you please use Eclipse for the same article

  44. Anonymous says:

    Nice, could you please use Eclipse for the same article

  45. JARV says:

    Excelent tutorial!!!!!man congratulations!!!! I like it!! (Y)

  46. Azahrudhin says:

    Hi guys can you share the example for the soap webservice producer and client with cxf please.
    producer will expose method exec(Map params);
    client will access the webservice using wsdl say
    soapWsClient = new SoapClient(“url of wsdl”);

  47. Santhosh Kuamr says:


    Could you please tell me what component contains SOA and what is JAX-WS and RPC and how to use in soa project. I could not understand those thinks.

  48. vibin says:

    Very Good Explanation and easy to Understand..Thankuu Joe..All d best..:)

  49. Bikash says:

    Simple Explanation but I having some problem while creating Web Services Client. It says
    Problem with downloading wsdl or schema file.
    Check the URL, proxy setting or whether the server is running

  50. Ashish says:

    Sir,could you provide the wsdl service in eclipse IDE

  51. […] the service is web service provider and the one utilizing it is web service consumer. In a previous hello world tutorial for web service we discussed about creating a service based on soap using Netbeans. This micro tutorial will help […]

  52. Anonymous says:

    Simple and superb example to understand basic knowledge for WS.


  53. Anonymous says:


    Don’t we need to publish the end point of the webservice ?


  54. suresh says:

    HI we need same example in eclipse IDE, Can you please provide in eclipse tooo?

    Any one can provide same example in Eclipse too….

  55. leela says:

    good one

  56. prakash says:

    Sir I created WebService but after creation i run the project… and type the url http://localhost:8080/SOAPHelloWorld/HelloWorld?wsdl.. it is showing 404 error.. what can i do. please explain

  57. venkat says:

    It is good article..

  58. hema says:

    its is really good artical .. i am going to start..

  59. hema says:

    hey i tried many times with eclipse but unable to create .
    can you provide other document for eclipse also.

  60. Prasad says:

    Hi Joe,

    Thanks for giving this blog.This is very helpful for me.

  61. Sony says:

    It’s a nice paper to get understanding of what is webservices and purpose.
    Thanks alot Joe.

  62. […] Eclipse wizard to generate the web service and client. Previously I wrote a tutorial to create a java web service using NetBeans and based on popular request I am writing this […]

  63. Anonymous says:

    hi Joe,

    Can you tell the steps to create RestFull web service?

  64. Shweta says:

    Can you please sugget somthing on this?

    Facing one issue in consuming a webservice using CXF client. I had made a class to consume web service in which there is a line:
    Client cli = ClientProxy.getClient(port); Here Client is of type org.apache.cxf.endpoint.Client;
    ClientProxy is of type org.apache.cxf.frontend.ClientProxy;
    And port is coming of type
    org.apache.axis2.jaxws.client.proxy.JAXWSProxyHandler@685d685d but port must be of type org.apache.cxf.jaxws.JaxWsClientProxy@114d114d. Don’t know why this mismatch is coming?Even axis2 jar is not there .

    For all this I am using RAD with wepshere as server

  65. REST vs SOAP says:

    […] SOAP has a standard specification but there is none for REST. […]

  66. uttam says:

    will you plase share a book name to study web services using apache axis4 for begginers.

  67. Joe says:

    “Java Web Services: Up and Running by Martin Kalin” is a nice book for java web services in general. For learning Axis, go by their documentation.

  68. Joe says:

    Publishing to UDDI is always optional.

  69. Joe says:

    Ensure you have properly deployed the application and check for any errors in the server log.

  70. Joe says:

    sure, we will see more on web services

  71. Jaimal Singh says:

    Good work keep it up…

  72. swapnil says:

    Joe is really genious…Thank u very much…
    you are real guid to educate programmer…

  73. Anonymous says:

    can any 1 say d actual input and the output that we should get

  74. Anonymous says:

    can the admin say d actual input and the output that we should get

  75. Anonymous says:

    where the flow starts and ends?

  76. dinesh says:


  77. Ghufran says:

    Great tutorial…keep it up sir

  78. Kishore says:

    Superb explanation :) thank you so much

  79. sravs says:

    Thank you so much Joe

  80. Srinivas says:

    Good Article. Explained nicely the simple example. can you suggest any online books for SOAP in JAVA for free

  81. mark says:

    Hi Joe, Since we people are moving towards RESTful Web services as current trend Can You explain the same process in REST Web service

  82. Lakshmi says:

    Excellent Joe, thanks for the wonderful article on web services.

  83. senthil kumat says:

    I have used Netbeans IDE But after this step
    (click choose “Web Service Client Resources” then select “Call Web Service Operation…”)i got the dialog with There is no WS references

  84. raj says:

    This is really good. I have not yet read entire article, but just wanted to appreciate here after reading these below lines. ” Web service is an interface for your software. We may have web user interface or a thick client (desktop) user interface for our software. Imagine web service as another similar interface. This interface is not for humans but for softwares.

    Web/thick client directly serves end user as an interface to interact with the software. Web service serves as an interface to software developers.”

    Very nice and simple explanation

  85. Prashant Gupta says:

    The above example revised by web-services concepts.
    Perfect explanation for beginners.

    Can you please provide the example on RestFull webservice in eclipse?

    Thanks in Advance.

  86. Sathya says:

    I tried deploying in Tomcat 6.0.16 from netbeans 6.1 IDE, it’s not working. I’m getting the error as Throwable occurred: java.lang.IndexOutOfBoundsException

    Please clarify.

  87. Joe says:

    Post the complete stack trace of the exception.

  88. balamurugan says:

    nice artical keep it up.

  89. Bao says:

    Nice tutorial, thanks a lot

  90. Surendra kumar says:

    I have to access a java swing application which is on server machine from a java web application
    Please help me.
    I have to send few attributes tu Gui apps and in turn retrieve result from that..

  91. saurabh says:

    Check your Eclipse is 32 or 64 bit. Download Eclipse according to Window,Linux or Mac OS (32 or 64 bit version)…

  92. Great says:

    It was helpful for my Hello World :),Excellent

  93. vinod says:

    Really Super Jeo, it is working for me.. thanks a lot

  94. Samuel says:

    good one to start with. Keep giving more

  95. VNP says:

    all your tutorials r really good nd easy to learn,,,,,

  96. Anonymous says:

    Hi joe ,

    your explanation is awesome. I would request you could you please add the hibernate tutorial also ?

    thanks ,


  97. Joe says:

    Sure Ravi. I have plans for that and will write on Hibernate soon.

  98. N P Nagendra Rao says:

    Excellent Joe . I could be able to create Webservice and run it atlast. Thank You.

  99. Bittu says:

    sir do we need to install apache for this.

  100. Durga says:

    its really very good work out with simple example


  101. Prakash says:

    First thanks for this great article..
    When I tried this I have found some problem..
    I have followed your steps and developed SOAPHelloWorld Web Application.But when I tried to create web service it shows following error…
    FAIL – Deployed application at context path /SOAPHelloWorld but context failed to start
    E:\Project\Web Application\SOAPHelloWorld\nbproject\build-impl.xml:724:
    The module has not been deployed.
    at org.netbeans.modules.j2ee.deployment.devmodules.api.Deployment.deploy(
    at org.netbeans.modules.j2ee.ant.Deploy.execute(

    Tomcat 7.0
    IDE:Netbeans 7.0

  102. Bhushan says:


    Which is best web service & using by company in real project ?

  103. Umer says:

    Its tomcat error, in tomcat change theServerlocation to use Tomcat Installation

  104. Tunji says:

    Launch the task manager and end the java.exe processes you have there. Then try to restart netbeans. If this does not work, you may try to recreate your application and run your application after every step.

  105. Jyo says:


    I have few issues while trying to connect to SOAP WSDL through client using security protocol .It gives a data element error thought the data element is in live with the schema and the validation is ok when checked through SOAP UI.
    pls suggest.


  106. Shiv says:

    Hi Joe,

    Could you share REST based web application for saving a record into MySQL Database.


  107. Jinesh says:


    You write web service and then called and you got reponse.

    You did not put any Xml in the method along with the other code.When should we use xml and why in the webservices.Can u please reply

  108. Raj Solanki says:

    I am not able to install the weblogic server in my computer can you help me out with this??

  109. Durgaprasad Perumalla says:

    Hi Sir,
    the basic idea about webservice is good, but plz extend the tutorial with more ….
    Thank you very much
    Durgaprasad Perumalla

  110. chandu says:

    please any one can help me to write remote client to invoke JWS web service in eclipse.

  111. anar says:


  112. Alex Dan Dodu says:

    Thank you Joe for soap-web-service-introduction. It helped me a lot!. Thank you very much. Good luck.

  113. xubing says:

    this is what I need, thanks a lot!

  114. lnc says:

    simply superb…nice article

  115. sand says:

    Really good tutorial, Thank you.

  116. sugu says:

    i have error while running this webservice which i downloaded from your website….

  117. paragflume says:

    Hi Joe,

    Can you please upload an example of complex data type. Like to to send and receive a Person object. Person object will contain name, address properties etc. How to use the tag in this case. Can you please send me a sample source code project for the complex data type


  118. daniel says:

    where did you find those plugins at?

  119. Swati says:

    Its really very nice example. Thank you very much sir. Please keep on posting some nice easy examples so that anybody can learn JAVA and other J2EE concepts.

    Thank you so much…

  120. hi joy says:


  121. Atmprakash SHarma says:

    i, joe , first off all Thnaks for making the blog .can you please mpre emphasize on wsdl and background technology used in Soap. I am using JDEV.

    I ,Like al you blogs..sipmle easy, intractive…each and every night whwver i am going to sleep.i used to check this.nice.

  122. Joe says:

    Welcome Atmprakash.

    Sure, I have plans to write more on web services SOAP and REST. Will write about them soon.

  123. Joe says:

    Thanks and sure Swati.

  124. Swati says:

    Hi Joe,

    Do you know how i can point my web-service to the jdk 1.6 inherent saaj implementation ?

    My web-service runs fine under tomcat but creates a conflict when deployed in a different server that’s using jdk 1.6

    How can i make my web service to run using the soap implmenetation provided by jdk1.6 rather then using the saaj-impl.jar file under WEB-INF/lib folder ?

  125. Monish Sen says:

    JMS is message driven i.e information is exchanged in the form of messages. It is ideal for middleware

    WebServices use various medium like (xml/json/plaintext) to communicate. It is ideal for client server scenario

  126. Monish Sen says:

    Nice and informative post. However I must say, usually the question REST vs SOAP is typically seeking comparison between the two different ways of writing ‘WebServices’, not a literal comparison of the concepts themselves. As you yourself said, they are entirely different things

  127. karthi says:

    Hi Joe, I tried your example and i added my own methods with the default hello method and from the JSP page I am passing String values to those methods. I am facing a problem here, when I passed a value for the default hello method it prints the value in the browser but for the method I defined it is not printing it in the browser and I tried SYSTEM.OUT.PRINTLN inside the method and it prints it in the console. I am unable to figure out where the problem is. Please help me out.

    And For Your Information this is the first webservice code I am writing. Thanks in advance

  128. Karthi says:

    Hi I am trying to consume a webservice and I created a client to consume it. I have a problem here. When I try to call the method from the client with parameter, the parameter they are used of the type user defined class. But the input I have to give is a String. How can I convert it to the user defined class type..Please help

  129. Shankar says:

    Its nice example sir but can please provide example for top down approch

  130. Aabid Husain says:

    Very nice example, never will be found anywhere like this one….

  131. srijini says:

    i need your immediately help .
    i developed a web service in netbeans using TOMCAT as server. but i couldnt test this service (the Test Webservice and Refresh options are disabled). i searched google for the solution but didnt find . please give the sln. its urgent.


  132. Srikanta Mukherjee says:

    When i try to Create Webserice cilent its showing following error:
    File not found in the specified address : http://localhost:8080/SOAPHelloWorld/HelloWorld?wsdl

    Plz me help me out of this

  133. pranav says:

    How do we create SOAP Web Services – bottom up approach in java using eclipse and weblogic server. Request your assistance as soon as possible.

  134. Yuvraj says:


    Superb,simple and understandable example that i have ever seen… thanks a lot… please keep go with these kinds…

  135. rajkumar says:

    Hi Joe

    I want consume SAP wsdl file in java application Please help me it is urgent requirement

  136. Naren says:

    Can you provide me a SOAP based Web service using database in java

Comments are closed for "Soap Web Service – Introduction".