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.
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
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 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.
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.
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.
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.
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.
Now right click the project and click run. Then type the following url in the browser
http://localhost:8080/SOAPHelloWorld/HelloWorld?wsdl
it will return the wsdl of the soap web service that we have created now. This wsdl contains,
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.
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 are closed for "Soap Web Service – Introduction".
super ….
hello sir,
whenever i installed the eclipse i will give
error “Failed to load JNI Shared Library ”
Please tell me
hello there,
i hope you make a paper about jax-ws and BPEL :D
“I have chosen Eclipse as my IDE” and then you use NetBeans.
HI we need same examle in eclipse IDE, Can you provide in eclipse?
Hi,
Its really good and simple example to start with for WS beginners.
Thanks,
Ravinder
Hi,
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
yours:
ismail
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
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.
This seems very clear. Good explanation Joe..Thank you very much.
please explore more. like How service is build and defining XSD with WSDL example.
Thanks
Navaz. shaik
super….
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”));
Joe,
Great article.!
can you please explain, writing web service (SOAP) without IDE too!
Hi,
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.
Thanks alot Joe
Hi,
sir can you help me how to use cvs tools
in myeclipse..
debasish on 13th 2012 6.40 pm
Hi,
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(Utils.java:531)
at org.apache.axis2.description.OutInAxisOperationClient.handleResponse(OutInAxisOperation.java:375)
at org.apache.axis2.description.OutInAxisOperationClient.send(OutInAxisOperation.java:421)
at org.apache.axis2.description.OutInAxisOperationClient.executeImpl(OutInAxisOperation.java:229)
at org.apache.axis2.client.OperationClient.execute(OperationClient.java:165)
This service works fine with Axis1 and SOAPUI tool but not with Axis2. Can anybody please help me in this?
Thanks in advance,
Raghu
Hi joe,
this is sivaram . i am new to webservices
can u give me a simple example to learn the webservice in eclipse.
Simply Superb
hi,
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
Amar
Hi,
Your i have one question.
Soap based services generate xml to communicate.
What about Restful services..
This is very useful for me….
we need example using myeclipse
Thanks Joe
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
I like it so much… what a gr8 stuff to learn… i really appriciate this.
Could you kindly explain the differences between JMS and Web Service and when the JMS and Web Service will be used?
hi mr joe my apache tomcat is not creating cache
Hi Sir
Using handlers i have intercepted my SOAP Response for attaching my hash value.now i want to send this SOAP response to client.
[…] 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 […]
[…] 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 […]
Hi,
Its very much understandable.
But I need this thing in Eclipse. And I’m working with th OS Ubuntu.
Thanks,
Praveen
Hi joe ,
I learned a lot from your articles. Can you please post an article regarding webservices security and restful webservices in detail.
Joe, You rock! Thumbs up for you !
Joe You are rock! can you give some more examples?
in wsdl file what is uses of minOccurs=”0″ and maxOccurs=”ünbounded” ?
Hi,
I am fresher.
I facing so much problem while learning SOAP.This site is really usfull for me..
Thanks..
Neha
Very Helpful information..above all a very excellent way of presenting the information.
Keep up the good work…all the best cheers..:)
Nice article. Can you also post one for Rest WS.
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.
thanks
NICE tutorial
Joe,
Can you please suggest any books on the webservices. I am novice to Webservices. Want to know more about it.
Thanks,
Nice, could you please use Eclipse for the same article
Nice, could you please use Eclipse for the same article
Excelent tutorial!!!!!man congratulations!!!! I like it!! (Y)
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”);
soapWsClient.check(Map);
Hi,
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.
Very Good Explanation and easy to Understand..Thankuu Joe..All d best..:)
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
Sir,could you provide the wsdl service in eclipse IDE
[…] 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 […]
Simple and superb example to understand basic knowledge for WS.
Thanks
Sreeni
hi,
Don’t we need to publish the end point of the webservice ?
BestRegards,
Raj.
HI we need same example in eclipse IDE, Can you please provide in eclipse tooo?
Any one can provide same example in Eclipse too….
good one
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
It is good article..
its is really good artical .. i am going to start..
hey i tried many times with eclipse but unable to create .
can you provide other document for eclipse also.
Hi Joe,
Thanks for giving this blog.This is very helpful for me.
Hi,
It’s a nice paper to get understanding of what is webservices and purpose.
Thanks alot Joe.
[…] 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 […]
hi Joe,
Can you tell the steps to create RestFull web service?
Hi,
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
[…] SOAP has a standard specification but there is none for REST. […]
will you plase share a book name to study web services using apache axis4 for begginers.
“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.
Hema, take this
https://javapapers.com/web-service/java-web-service-using-eclipse/
Publishing to UDDI is always optional.
https://javapapers.com/web-service/java-web-service-using-eclipse/
Ensure you have properly deployed the application and check for any errors in the server log.
sure, we will see more on web services
Good work keep it up…
Joe is really genious…Thank u very much…
you are real guid to educate programmer…
can any 1 say d actual input and the output that we should get
can the admin say d actual input and the output that we should get
ADMIN:
where the flow starts and ends?
lol
Great tutorial…keep it up sir
Superb explanation :) thank you so much
Thank you so much Joe
Good Article. Explained nicely the simple example. can you suggest any online books for SOAP in JAVA for free
Hi Joe, Since we people are moving towards RESTful Web services as current trend Can You explain the same process in REST Web service
Excellent Joe, thanks for the wonderful article on web services.
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
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
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.
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.
Post the complete stack trace of the exception.
Hi,
nice artical keep it up.
Nice tutorial, thanks a lot
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..
Check your Eclipse is 32 or 64 bit. Download Eclipse according to Window,Linux or Mac OS (32 or 64 bit version)…
It was helpful for my Hello World :),Excellent
Really Super Jeo, it is working for me.. thanks a lot
good one to start with. Keep giving more
all your tutorials r really good nd easy to learn,,,,,
ThankQ
Joe……
Hi joe ,
your explanation is awesome. I would request you could you please add the hibernate tutorial also ?
thanks ,
Ravi
Sure Ravi. I have plans for that and will write on Hibernate soon.
Excellent Joe . I could be able to create Webservice and run it atlast. Thank You.
sir do we need to install apache for this.
its really very good work out with simple example
Thanx
Joe,
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(Deployment.java:187)
at org.netbeans.modules.j2ee.ant.Deploy.execute(Deploy.java:106)
at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:291)
Tomcat 7.0
IDE:Netbeans 7.0
Hello,
Which is best web service & using by company in real project ?
Its tomcat error, in tomcat change theServerlocation to use Tomcat Installation
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.
hi,
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.
Thanks
Hi Joe,
Could you share REST based web application for saving a record into MySQL Database.
Thanks,
Shiv
Hi,
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
I am not able to install the weblogic server in my computer can you help me out with this??
Hi Sir,
the basic idea about webservice is good, but plz extend the tutorial with more ….
Thank you very much
Durgaprasad Perumalla
please any one can help me to write remote client to invoke JWS web service in eclipse.
wah
Thank you Joe for soap-web-service-introduction. It helped me a lot!. Thank you very much. Good luck.
this is what I need, thanks a lot!
simply superb…nice article
Really good tutorial, Thank you.
i have error while running this webservice which i downloaded from your website….
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
Thanks
where did you find those plugins at?
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…
thanks
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.
Welcome Atmprakash.
Sure, I have plans to write more on web services SOAP and REST. Will write about them soon.
Thanks and sure Swati.
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 ?
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
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
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
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
Its nice example sir but can please provide example for top down approch
Very nice example, never will be found anywhere like this one….
hi,
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.
thanks
Srijini
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
How do we create SOAP Web Services – bottom up approach in java using eclipse and weblogic server. Request your assistance as soon as possible.
Ji…
Superb,simple and understandable example that i have ever seen… thanks a lot… please keep go with these kinds…
Hi Joe
I want consume SAP wsdl file in java application Please help me it is urgent requirement
Can you provide me a SOAP based Web service using database in java