1. Create java web service in Eclipse using Axis2 (Part 01)
2. Create java web service in Eclipse using Axis2 (Part 02)
Before implementing the client first we have to find the wsdl file.
First run the created project on Tomcat server. To do this right click on project select Run As then select Run on Server.
Click on Services
Select Hello which is your web service class name. Under Available Operations you can see your web service operation.
After clicking on Hello you can see the WSDL file. Copy WSDL link to the clip board.
OK. We coppied the WSDL link.
Now we have to create the web service client.
Right click the web service class select New >> Other >> Web Services >> Web service Client.
Click Next. Paste link of the wsdl file to the Service definition box. (If you want to access the wsdl in another computer via a net work replace "localhost" in the WSDL url with the ip address of the server machine)
Make sure that the Server runtime is Tomcat & the Web service runtime is Axis2 by clicking the links underlined red color in the following diagram.
Client type : Java Proxy
Click finish to generate Callback Handler & the Stub in same package where the web service class exists.(If you want to change the client package click next & give a package name to Custom package name as you wish)
Then create new class. Class name that I used is Client. Here is the project structure.
Following code shows how we can invoke the web service method using auto generated Stub. Paste this code to newly created class. This client class also in the same package with web service class.
package org.webapp.ws; import org.webapp.ws.HelloStub.SayHello; public class Client { public static void main(String[] args) throws Exception { HelloStub stub = new HelloStub(); //Creating the request org.webapp.ws.HelloStub.SayHello request = new org.webapp.ws.HelloStub.SayHello(); request.setName("Java web"); //Invoking the service org.webapp.ws.HelloStub.SayHelloResponse response = stub.sayHello(request); System.out.println("Response : " + response.get_return()); } }
Right click Client class and run the client as a java application.
Result :
Click here to download the complete project with client.
If you find this post helpful don't forget to leave a comment. Your comments always encourage me to write more!
Happy coding!
Thanks sooooooooooo soooooooo soooooo much
ReplyDeleteThanks soooo much, I can able create and run the web service... It is very use full.
ReplyDeleteThe HelloStub.java is showing errors, how these can be fixed? "Multiple markers at this line
ReplyDelete- HashMap is a raw type. References to generic type HashMap should be
parameterized
"
Hello!! the tutorial is really very nice. But I am getting the following error in HelloStub.java class, how it could be resolved?
ReplyDeleteMultiple markers at this line
- HashMap is a raw type. References to generic type HashMap should be
parameterized
Thanks buddy ..really useful..........
ReplyDeleteHello. I've a problem on the line "request.setName("Java web");". setName is undefined for the type HelloStub.SayHello.
ReplyDeleteAny solution?
Thanks :-)
Great tutorial, but I get the following error in Client class on :request.setName("Java web"); setName is not defined ;
ReplyDeleteAny solution???
Thanks.
This is a very good tutorial!
ReplyDeleteExcuse me.. I followed the whole process (all 3 parts..)
ReplyDeleteand when I´m running the client class as a java aplication I have this error:
Exception in thread "main" org.apache.axis2.AxisFault: unknown
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)
at org.apache.ws.BaseDatosWSStub.digaHola(BaseDatosWSStub.java:197)
at org.apache.ws.Client.main(Client.java:18)
I followed the whole tuotrial.. the 3 parts and when I´m running the client class as a java application I come across this message:
ReplyDeleteException in thread "main" org.apache.axis2.AxisFault: unknown
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)
at org.apache.ws.BaseDatosWSStub.digaHola(BaseDatosWSStub.java:197)
at org.apache.ws.Client.main(Client.java:18)
i tried this code... when i run andriod file the emulator shows force close...i changed all the things..but not working
ReplyDeleteThank You Soooooooo Much ... By the way is this Soap/rest web service ?
ReplyDeleteThank You So Much. By the way is this rest or soap web service?
ReplyDeleteExcellent work, I followed the two example and both of them worked properyly with zero problem.
ReplyDeleteThanks Paiya....
ReplyDeleteThank You So Much...
ReplyDeleteusing this application we can run with in eclipse only we can reflect actual Tomcat server
My Question is how can deploy our app in Tomcat_Home/webapps/axis2/our app of our local mession
Thank in advance....
Thank You So Much
ReplyDeleteI Have a Small Question ..
using this we can deployee our app in eclipse only but not in local Tomcat server
i mean not in Tomcat_Home/webapps/axis2/WebApp
How to reflect in tomcat local metion
thanks in advance...
your's Pavan R
can anybody help me ?i m not getting name of method in service list i.e. deployed web service i only got web service class name but when i get the page in browser it shows me no operation specified what is wrong there.
ReplyDeletei got this error:
ReplyDeletehttp status 404-
is there any modification required for web-INF of build.xml or other file required?
i got status 404 error after all above procedure.
ReplyDeleteis ther any other modification required in another folder/file like any xml file etc?
Hey the best tutorial i have ever found . Please can u explain me how it is working.I didn't understood the flow of code. how it it connected to the webservice class. The three class has been generated what is the significant of those class.
ReplyDeleteHey the best tutorial i have ever found . Please can u explain me how it is working.I didn't understood the flow of code. how it it connected to the webservice class. The three class has been generated what is the significant of those class.
ReplyDeletePlease tell me how to find soapAction from generated wsdl file.Please help me .
ReplyDeletePlease help to find soapAction form created wsdl file or any other option
ReplyDeleteExcellent compilation, I could do to great extend except I did not understand
ReplyDeleterequest.setName("Java web"); in client code
suppose this is my class
public class Conv {
public double ftoC(double x)
{
return (5.0/9.0)*(x-32.0);
}
public double ctoF(double y)
{
return ((9.0/5.0)*y)+32.0;
}
}
what will be the possible client code?
Thank You So Much! The Brazilian Students thanks!
ReplyDeleteGreat Tutorials, tons of thanks!!
ReplyDeleteNice Job!! How can I use this web service from an android client!!
ReplyDeleteNice post
ReplyDeletewebsite designing company in india
Great article,gone through your page ,really it's an amazing and useful information.Thanks for sharing.
ReplyDeleteWeb Development in Bangalore|Website Designing Company Bangalore