Thursday, June 9, 2011

Create Web Service in Java Using Apache Axis2 and Eclipse



Web services are application components which communicate using open protocols. Using Web Services we can publish our application's functions to everyone. This tutorial provides step by step instructions to develop Web Services using Axis2 Web Services / SOAP / WSDL engine and Eclipse IDE. Let's start.

1. Setup the Development Environment


1.1. First you need to set up the development environment. Following things are needed if you want to create Web Services using Axis2 and Eclipse IDE.

Some Eclipse versions have compatibility issues with Axis2. This tutorial is tested with Apache Axis2 1.5.2, Eclipse Helios and Apache Tomcat 6.

1) Apache Axis2 Binary Distribution - Download
2) Apache Axis2 WAR Distribution - Download
3) Apache Tomcat - Download
4) Eclipse IDE – Download
5) Java installed in your Computer – Download

1.2. Then you have to set the environment variables for Java and Tomcat. There following variables should be added.
JAVA_HOME :- Set the value to jdk directory (e.g. C:\Program Files\Java\jdk1.6.0_21)
TOMCAT_HOME :- Set the value to top level directory of your Tomcat install (e.g. D:\programs\apache-tomcat-6.0.29)
PATH :- Set the value to bin directory of your jdk (e.g. C:\Program Files\Java\jdk1.6.0_21\bin)
1.3. Now you have to add runtime environment to eclipse. There go to Windows –-> Preferences and Select the Server --> Runtime Environments.


There select Apache Tomcat v6.0 and in the next window browse your Apache installation directory and click finish.


1.4. Then click on the Web Service –-> Axis2 Preferences and browse the top level directory of Apache Axis2 Binary Distribution.


2. Creating the Web Service Using Bottom-Up Approach


2.1 First create a new Dynamic Web Project (File --> New –-> Other…) and choose Web --> Dynamic Web Project.


2.2 Set Apache Tomcat as the Target Runtime and click Modify to install Axis2 Web Services project facet.


2.3 Select Axis2 Web Services


2.4 Click OK and then Next. There you can choose folders and click Finish when you are done.

3. Create Web Service Class


Now you can create a Java class that you would want to expose as a Web Service. I’m going to create new class called FirstWebService and create public method called addTwoNumbers which takes two integers as input and return the addition of them.

3.1 Right Click on MyFirstWebService in Project Explorer and select New –-> Class and give suitable package name and class name. I have given com.sencide as package name and FirstWebService as class name.

package com.sencide;
public class FirstWebService { 
 public int addTwoNumbers(int firstNumber, int secondNumber){
  return firstNumber + secondNumber;
 }
}
3.2 Then, select File --> New –-> Other and choose Web Service.


3.3 Select the FirstWebService class as service implementation and to make sure that the Configuration is setup correctly click on Server runtime.


3.4 There set the Web Service runtime as Axis2 (Default one is Axis) and click Ok.


3.5 Click Next and make sure Generate a default service.xml file is selected.


3.6 Click Next and Start the Server and after server is started you can Finish if you do not want to publish the Web service to a test UDDI repository.


You can go to http://localhost:8888/MyFirstWebService/services/listServices to see your running service which is deployed by Axis2. You can see the WSDL by clicking the link FirstWebService.


We have to use Eclipse every time when we want to run the service if we do not create .aar (Axis Archive) file and deploy it to the server. So let’s see how we can create it.

4. Create .aar (Axis Archive) file and Deploying Service


4.1 In your eclipse workspace and go to MyFirstWebService folder and there you can find our web service inside services folder. Go to that directory using command prompt and give following command. It will create the FirstWebService.aar file there.
jar cvf FirstWebService.aar com META-INF



4.2 Then copy the axis2.war file you can find inside the Apache Axis2 WAR Distribution (You downloaded this at the first step) to the webapps directory of Apache Tomcat. Now stop the Apache Tomcat server which is running on Eclipse IDE.


4.3 Using command prompt start the Apache Tomcat (Go to bin directory and run the file startup.bat). Now there will be new directory called axis2 inside the webapps directory. Now if you go to the http://localhost:8080/axis2/ you can see the home page of Axis2 Web Application.


4.4 Then click the link Administration and login using username : admin and password : axis2. There you can see upload service link on top left and there you can upload the created FirstWebService.aar file. This is equal to manually copping the FirstWebService.aar to webapps\axis2\WEB-INF\services directory.


4.5 Now when you list the services by going to http://localhost:8080/axis2/services/listServices you should be able to see our newly added service.


5. Creating a Web service client


5.1 Select File --> New --> Other… and choose Web Service Client


5.2 Set he newly created Axis2 Web service (http://localhost:8080/axis2/services/FirstWebService?wsdl) as the Service definition. Then configure the Server runtime as previously and click finish.


5.3 This will generate two new classes called FirstWebServiceStub.java and FirstWebServiceCallbackHandler.java. Now we can create test class for client and use our web service. Create new class called TestClient.java and paste following code.
package com.sencide;

import java.rmi.RemoteException;
import com.sencide.FirstWebServiceStub.AddTwoNumbers;
import com.sencide.FirstWebServiceStub.AddTwoNumbersResponse;

public class TestClient {

 public static void main(String[] args) throws RemoteException {
  
  FirstWebServiceStub stub = new FirstWebServiceStub();
  AddTwoNumbers atn = new AddTwoNumbers();
  atn.setFirstNumber(5);
  atn.setSecondNumber(7);
  AddTwoNumbersResponse res = stub.addTwoNumbers(atn);
  System.out.println(res.get_return());
  
 }
}
Now you can run the above code as java application and you will get the output as 12 since we are adding 7 and 5.
Download the Eclipse project of the above example (Password:sara)
Your comments are welcome !

144 comments:

  1. This tutorial is awesome dude !! works fine

    ReplyDelete
  2. Thank you very much. Can you help us on how to connect client side desktop application to server side web application(updating data to server side database)

    ReplyDelete
  3. Ha ha well done copy paste man ,you are pasting others tutorial to your nlog ,and saying thanks you are enjoying my blog .....gr* man gr8!!!

    what is new here !!!! bogas block and rediculous you!!!

    ReplyDelete
    Replies
    1. Don't say like this. This may not be useful to you. But this is really valuable for us...

      Delete
    2. This is very useful don't ever say to anyone...

      Delete
  4. @ gaurav,
    I haven't done copy paste thing here. If so, why don't you tell from where I have copied. So I don't accept your abuse and you can keep it with you.
    Thanks for commenting...

    ReplyDelete
  5. @ Payam,
    You are welcome, thanks for commenting...

    ReplyDelete
  6. Hi,

    Based on these steps we created a web service that talk with server side database from client application. The data is passed as string array and the query is executed with executeUpdate() of prepared statement say 'ps'. But , the ps.executeUpdate() is not getting executed. There are no errors or exception shown.

    Could you please help us on this.

    ReplyDelete
  7. I am so so happy.
    Thanks for this wonderful effort. So accurate and profound.

    agsthya.tumblr.com

    ReplyDelete
  8. Hi,
    I had few problems while doing this example
    1) As in section when we run type the url
    http://localhost:8888/MyFirstWebService/services/listServices in the browser, i could not see the operations avalable
    It is displaying no operations available

    2) i could not find the axis2.jar to deply on the webapps folder as in section 4.2

    Please help

    Thanks
    Suman

    ReplyDelete
  9. the tutorial work fine for me, thank you very much

    now i'm looking for sucure ws by integrating java key store (jks) for encrypting data exchange between client and service side..
    any one have a goog tutorial to doing it

    thank you in advance

    ReplyDelete
  10. @moments,
    Thanks for commenting...

    @suman,
    It is not "axis2.jar" but "axis2.war" which I have given the download link. :)
    Please add it and try again.
    Thank You !

    ReplyDelete
  11. Hi Saranga

    I need to skip the home page of Axis2 so that i directly get my WSDL when i run my project(Web Service). Is there any way to do this task.
    Thanks in advance.

    Asim Khan

    ReplyDelete
  12. why i am getting this error :(

    IWAB0489E Error when deploying Web service to Axis runtime
    axis-admin failed with {http://schemas.xmlsoap.org/soap/envelope/}Client The service cannot be found for the endpoint reference (EPR) http://localhost:8080/webservicde/services/AdminService

    ReplyDelete
  13. @ AS OnE JoUrNeYEnD, AnOtHeR BeGiNs,
    Some Eclipse versions have compatibility issues with Axis2. Please try with Apache Axis2 1.5.2, Eclipse Helios and Apache Tomcat 6.
    Thanks !

    ReplyDelete
  14. this is a wonderful tutorial.. neat and clearly explained.. followed step by step instruction and result was success.. great.it wud be great if you include top-down approach also. that will make a complete blog on axis2 webservices. Also would like to know about the usage of stubs and handler files created. So that all can understand.

    On the whole, was searching for a good tutorial on Axis 2 and got here. Great one.kudos.

    ReplyDelete
  15. i followed this tutorial as described,but got this error at the time of project creation.
    Failed while installing Axis2Web Services Core 1.1.
    I used these versions.
    eclipse Helios
    apache-tomcat-6.0.33
    jdk1.6.0
    axis2-1.5.2
    need help....

    ReplyDelete
  16. @ hamaresan,
    You are welcome, I'll try to update this post for that also. Stubs and handler classes are used in your client application. Thanks for commenting...

    ReplyDelete
  17. thank you very much for this basic and step by step tutorial. i'm very new in web services, it will be very useful for me.

    ReplyDelete
  18. @ neha,
    Please check,
    Eclipse - Windows - Preferences - web services - Axis2 - Axis2 runtime location is set properly, if not you have to set the path correctly.

    @ cey,
    Thank you very much for commenting...

    ReplyDelete
    Replies
    1. Hi Saranga,

      i have the same as Neha problem while creating Dynamic web project. Pls, help me in this part.

      Delete
  19. If i publish my service on the internet, and want to access it through the internet(not localhost), how my TestClient looks like? I mean how can i connect to the web service and then send data and get result? Thank you in advance.

    ReplyDelete
  20. @ cey,
    You only need to change the URL to wsdl. please find the URL to the wsdl and continue with step 5.1.
    Thank You !

    ReplyDelete
    Replies
    1. Hi, can you explain it in more details? I got confused somewhere.

      http://localhost:8080/axis2/services/FirstWebService?wsdl

      Is it we have to change localhost:8080 to the server's IP in step 5.2?

      Thanks.

      Delete
  21. Hi,
    My service is showing as faulty. It was working through eclipse but not working using .aar file.
    What could be the problem??

    Available services

    Version

    Service Description : Version

    Service EPR : http://localhost:8080/axis2/services/Version

    Service Status : Active


    Available Operations
    getVersion
    Faulty Services

    C:\Program Files\Apache Software Foundation\Tomcat 7.0\webapps\axis2\WEB-INF\services\FirstWebService.aar

    ReplyDelete
  22. Hello,

    Both axis2 binary and war links are pointing to the same page. Why should we have the same software in two distributions. Please explain. Its confusing.

    ReplyDelete
  23. Dear Saranga,

    Its very good and helpful article. Keep it up.

    Could you please help to share some stuff to create SOAP message, which contains the database content in xml form.

    Best Regards,
    Brij

    ReplyDelete
  24. This tutorial is awesome, helped me for starting of with axis2 easily and i would welcome more examples and the link of other examples in every example to navigate easily.

    Thanks

    ReplyDelete
  25. Hi,
    I have to develop a web service using Axis2 and Tomcat Server based on a simple java class, in class their are some methods doing some task (communication to a server and returning response), for that i used a connection pool , In class a method called setUp() which used to initialize the connection pool , before communicating to server by other methods , it is necessary to call setUp() to initialize . How can i do the setUp() method is called when automatically when web service is loaded or started (i am not using servlet or jsp).

    ReplyDelete
  26. Dear Saranga!!
    Awesome tutorial!!could u also upload some videos on Youtube with ur tutorials!!
    Thanx in Advance!!

    ReplyDelete
  27. Hey Saranga
    Awesome tutorial!!could u please post some tutorial viedeos on youtube!!

    thanx in advance

    ReplyDelete
  28. while i am creating the Dynamic Web project ,the project facets was not installed properly and shows the below error message:
    'Failed while installing Axis2 webservices core 1.1'

    ReplyDelete
  29. I have created the web service as mentioned and then i added hibernate features to the web services method (simply add to addTwoNumbers method)
    then i placed the hibernate.cfg.xml and all the xml mapping files inside the .. all were compiled well.. but when i created a web service client and accessed the web service ... it error prompt like this,

    java.lang.ClassNotFoundException: org.hibernate.cfg.Configuration

    it wont load the hibernate classes when the tomcat starts.... what was the wrong??? thank u

    ReplyDelete
  30. Thanks for the post!

    Is itpossible to create axis 2 client in java standalone application rather than in web?

    ReplyDelete
  31. Hi Saranga,

    This tutorial is very nice... But
    exception is occured for me...Colud you help me!!!

    Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/http/HttpResponseFactory
    at org.apache.axis2.transport.http.SimpleHTTPServer.init(SimpleHTTPServer.java:113)
    at org.apache.axis2.engine.ListenerManager.init(ListenerManager.java:83)
    at org.apache.axis2.client.ServiceClient.configureServiceClient(ServiceClient.java:165)
    at org.apache.axis2.client.ServiceClient.(ServiceClient.java:144)
    at com.FirstWebServiceStub.(FirstWebServiceStub.java:91)
    at com.FirstWebServiceStub.(FirstWebServiceStub.java:77)
    at com.FirstWebServiceStub.(FirstWebServiceStub.java:126)
    at com.FirstWebServiceStub.(FirstWebServiceStub.java:118)
    at com.TestClient.main(TestClient.java:19)
    Caused by: java.lang.ClassNotFoundException: org.apache.http.HttpResponseFactory
    at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:303)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:248)
    at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:316)
    ... 9 more

    ReplyDelete
    Replies
    1. http://mirrors.ibiblio.org/pub/mirrors/maven2/org/apache/httpcomponents/httpcore/4.0.1/httpcore-4.0.1.jar

      Download the and put the jar file in lib folder.

      Delete
  32. Nice Tutorial for web service beginners

    ReplyDelete
  33. Thnks brother.. It was a great help..

    ReplyDelete
  34. Thanks a loot . iam a beginner and it was like a cake walk for me by just seeing the screen shots

    ReplyDelete
  35. http://stackoverflow.com/questions/9699368/custom-java-object-as-parameter-to-a-web-service-method

    I am facing the above issue
    would appreciate any help!

    ReplyDelete
  36. During the last step(after 5.2) I was unable to see any namespaces, packages except for DataBinding(ADB). Do you think if there is any issue with eclipse, axis1.6 or anything else?

    ReplyDelete
  37. It Works perfect......Thanks for such an step by step tutorial......

    ReplyDelete
  38. Hi,
    Thanks Sara for this wonderful tutorial. I have a question. I am new to web services. I followed instructions, when I click Next at step 3.5. I dont get an pop-up where it says Start Server.

    Thanks
    Ajoo

    ReplyDelete
  39. Never mind I can see the start Button. Had to move the slider up..

    ReplyDelete
  40. I reached right to end now I am getting
    Faulty Services
    C:\apache-tomcat-6.0.35\webapps\axis2\WEB-INF\services\FirstWebService.aar

    Note I am using Axis 1.2

    ReplyDelete
    Replies
    1. Sorry for the late reply, Did you able to resolve this issue ?
      Please try with new Axis version.
      Thanks !

      Delete
  41. Hi Can U also explain how write handlers for the axis web service

    ReplyDelete
    Replies
    1. Sorry Rupa I haven't much experience in handlers, but this will help you. http://archive.devx.com/java/wrox/7159_chap04.pdf

      Delete
  42. i followed this tutorial as described,but got this error at the time of project creation.
    Failed while installing Axis2Web Services Core 1.1.
    I used these versions.
    eclipse Helios
    apache-tomcat-6.0.33
    jdk1.6.0
    axis2-1.5.2
    need help...

    I have setup webservice runtime as Apache Axis2 also.
    I have setup the jdk as java home in env. system variable
    Still getting the same error..

    Any can help me on this issue?

    ReplyDelete
    Replies
    1. Hi Ashish,

      1. First check whether you have set up the Axis2 Runtime correctly (Step 1.4)
      2. If problem exist, create new workspace and retry.
      3. If it doesn't help, try this tutorial with new version of eclipse and axis2.
      Please post here if you could find a solution.
      Thanks !

      Delete
  43. great article malli...it's woking fine.

    ReplyDelete
  44. perfect. I use STS, Axis2 and Tomcat6. Thanks a lot.

    ReplyDelete
  45. It is really nice tutorial.It would be more better if you xplain bit more.like why we need Stub data?what is stub data and so and so....

    Cheers!!!
    Pritam(Bangalore)

    ReplyDelete
    Replies
    1. Thanks Pritam, I'll add more details in future posts.

      Delete
  46. Great Job. Finally I learned how to write a web service in Java using axis2. Thanks a lot.

    Regards,
    Jeyan

    ReplyDelete
  47. hi! great tutorial.
    but when i browse for http://localhost:8888/MyFirstWebService/services/listServices
    it doesn't connect to the link. chrome gives an error. what can i do for that?
    Thanks

    ReplyDelete
    Replies
    1. Please try http://localhost:8080/MyFirstWebService/services/listServices
      Your server may using port 8080

      Delete
  48. Hi Saranga,

    your tutorial is very useful for me but i have one query ??

    1. i want to create web service client from wsdl file using axix2. can you tell me where wsdl file get stored on server.

    ReplyDelete
  49. Very great, very clear, I will keep it in my favorites !

    ReplyDelete
  50. only one mistake in the entire tutorial.....http://localhost:8888/MyFirstWebService/services/listServices should be
    http://localhost:8080/MyFirstWebService/services/listServices

    that's it ...lovely though....

    ReplyDelete
  51. You Rock!! very precise, very clearly explained. Thank you so much!!!

    ReplyDelete
  52. Hi Saranga,

    firstly i would like to thank you for this Example. very precise, good explained!
    i would like to get Data from a Webservice. So i have to write a web service client. As a client/consumer, i don´t have to use the server Tomcat? i have to make it with Java and axis2...
    i get the wsdl document from the web service that i have to call. I generate it ( with wsdl2java) and i get a Build.xml...
    now i don´t know how to connect to the web service!
    can you please put some Light on this!
    Thanks in advance

    ReplyDelete
  53. hi , i got stuck up in the last step(5.2) while creating the webservice client ,when giving the service definition it is saying it is invalid.i checked many times but couldn't fix it.please help.

    ReplyDelete
    Replies
    1. (http://localhost:8080/here give ur project name/services/FirstWebService?wsdl

      Delete
  54. Working Perfectly!!!!
    Thanks for Posting

    ReplyDelete
  55. I know this is an older post but is it possible for Axis to return a JSON string without the SOAP wrapper? I've been looking all over for how to do this.

    ReplyDelete
  56. nice work and whts the use of axis2 war file?
    is it for web services deployment or some other thing ?

    ReplyDelete
    Replies
    1. It is is required to run Axis2 as part of a J2EE compliant servlet container.

      Delete
  57. This is the best tutorial i hv seen ever. :-)
    Thank you so much!!!

    ReplyDelete
  58. Why i can't se the "Axis2 Preferences" in the section "WEB Services"? Help me anybody please .

    ReplyDelete
  59. Everything worked fine and finally when creating Web Service Client below error is displayed in eclipse.
    "Exception occurred during code generation for WSDL : org.apache.axis2.AxisFault: No operation found in the portType element".

    ReplyDelete
    Replies
    1. Hi,
      Did you able to solve the problem? May I know the eclipse and Axis2 version that you are using.

      Delete
    2. Hi,
      i have the same problem. Did you able to solve it? i use eclipse helios and Axis2 1.5.2 versions. I'm waiting for your replies.
      Thank you in advance.

      Delete
    3. Hey,
      I did run into the same problem. Following did work for me. By providing a full domain name I was able to solve that issue; I.e. 'com.example.test'. Before I was using 'example.test' without 'com' as package name for the web service class and the web service client generation was always failing.

      Delete
  60. Good tutorial, perfect to start doing your first axis2 application.
    Things get complicated when implementing security, I have problems adding rampart module to do so.

    axis2 1.5.2
    rampart 1.5.1
    eclipse helios

    axis2.xml configuration:

    "


    Timestamp Signature
    soap

    es.clientetelefonica.integraciontercerosconfianza.PwCallback

    security.properties

    X509KeyIdentifier


    {Element}{http://schemas.xmlsoap.org/soap/envelope/}Body;
    {Element}{http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd}Created;
    {Element}{http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd}Expires


    "

    It doesn't like Body Element:

    Error during Signature: ; nested exception is:
    org.apache.ws.security.WSSecurityException: General security error (WSEncryptBody/WSSignEnvelope: Element to encrypt/sign not found: http://schemas.xmlsoap.org/soap/envelope/, Body)

    Do you have any tutorial for this?

    ReplyDelete
  61. Thats working good boss but at step 4.5 when i've uploaded the myClass.aar file ... the web service is being shown as a Faulty Services :(
    Any help plzzzz ??

    ReplyDelete
  62. hi sara,
    I created WebService as per your instruction and its working fine.Now that i want to invoke remote webservice i am getting following error.

    Unable to sendViaPost to url[http://www.webservicex.net/stockquote.asmx]
    org.apache.axis2.AxisFault: Transport error: 404 Error: Not Found

    i am new to WebService please help me.I tried setting proxy also even then i am getting this error.Also suggest me any nice tutorial or book for getting started.

    ReplyDelete
  63. Hi,

    I am trying to create a mobile application that requires URL to access the service, which I am not able to get from the wsdl file. Please let me know how to get the URL and also how to pass the parameters.

    ReplyDelete
  64. Hi,

    how can i update my or add more method to my web services? it is not updated in http://localhost:8080/axis2/services/listServices
    i had ran "jar cvf FirstWebService.aar com META-INF" and re-upload it to axis2, but still the same.

    any idea??

    ReplyDelete
  65. Hi!
    With me occurred this error: Exception occurred while reading or writing files A resource exists with a different case: '/WSservidor/src/com/WSservidor'.
    What`s this ?

    ReplyDelete
  66. I am using apache tomcat 6
    axis 2.1.5.2
    eclipse helios
    but i got following error in creating client
    Exception occurred during code generation for WSDL : org.apache.axis2.AxisFault: No operation found in the portType element


    pls help me ............

    thank u

    ReplyDelete
  67. Hi, Using these steps I am successfully created.
    Thank you very much.


    -Jeeva.

    ReplyDelete
  68. it is very helpful for all....yes really this tutorial is very useful for me.....now i have one doubts..how is insert dropdown value from android app to mysql database via soap webservices.please give me ideas.

    ReplyDelete
  69. Hi Sarang,

    This is really very Helpful for me.
    Thnx a lot buddy.
    But while Generating client im getting the following error :-

    Exception occurred while reading or writing files A resource exists with a different case: '/FirstWebSample/src/com/Value'.
    org.eclipse.core.internal.resources.ResourceException: A resource exists with a different case: '/FirstWebSample/src/com/Value'.
    at org.eclipse.core.internal.resources.Resource.checkDoesNotExist(Resource.java:329)
    at org.eclipse.core.internal.resources.Resource.checkDoesNotExist(Resource.java:307)
    at org.eclipse.core.internal.resources.Folder.assertCreateRequirements(Folder.java:30)


    Please suggest the way out.

    Thanks,
    Jaipreet

    ReplyDelete
  70. Hi Saranga,

    This is really very helpful for me.

    But i'm getting one problem while generating the client :-

    Exception occurred while reading or writing files A resource exists with a different case: '/FirstWebSample/src/com/Value'.
    org.eclipse.core.internal.resources.ResourceException: A resource exists with a different case: '/FirstWebSample/src/com/Value'.
    at org.eclipse.core.internal.resources.Resource.checkDoesNotExist(Resource.java:329)
    at org.eclipse.core.internal.resources.Resource.checkDoesNotExist(Resource.java:307)

    Please suggest for the same

    Thanks,
    Jaipreet

    ReplyDelete
  71. thanx for nice tutorial...bt same thing i want to devloped in android...can any 1 help me...?

    ReplyDelete
  72. Nice article and very explainatory. I have posted an article on "creating web services for beginners up and running in minutes" and also how to test their web services very easily in my blog http://helptodeveloper.blogspot.com/2012/09/testing-webservice-or-wsdl-with-soap-ui.html.

    ReplyDelete
  73. Could you please tell me how to capture saop messages through handler class?

    ReplyDelete
  74. This is a very useful document. Can also please share how to create a restful client for this webservice ?

    ReplyDelete
  75. Hi,

    Im stuck at Step 4.3 were in when I try to run the startup.bat, though the folder axis2 is created, the server is not running. So when I tried to access http://localhost:8088/axis2/, it returns 404 page. Please help. Thanks

    ReplyDelete
  76. Hi,

    At the step4.5 when i am running the browser with the followint URL htts://localhost:8080/axis2/services/listServices it is not displaying my services it is giving "Faulty Service" error.
    It is running wen i am running server in eclipse.

    i stucked here can u plz help me.

    ReplyDelete
  77. Hi Mr. Saranga Rathnayaka
    The tutorial is so good and i appreciate your effort.
    I actually work in dot net framework and now i have to work in java.
    In this tutorial, everything worked fine for me except one major proble:

    1) When i run tomcat from cmd after pasting war file in webapps folder of tomcat, according to your tutorial, axis2 folder should be created. But it is not created. I tried many times but in vain.

    Kindly guide me...
    Thanx in advance

    ReplyDelete
  78. Perfect !!! this really works. Great job!

    Just one question though, where do we see the SOAP messages? where to they get logged? I would like to see the request and response messages.

    -vijay

    ReplyDelete
  79. This is great. Thank you very much :)

    ReplyDelete
  80. Thanks a lot for this tutorial !!
    It's great :))

    ReplyDelete
  81. The generated FirstWebServiceStub is missing setFirstNumber and setSecondNumber. What could I possibly did wrong?

    ReplyDelete
  82. The generated FirstWebServiceStub is missing setFirstNumber and setSecondNumber. What could I possibly did wrong?

    ReplyDelete
  83. a very good article for beginners to start with Webservices. could you please upload some next level codes to do in Webservices?

    ReplyDelete
  84. if any of you interested in eclipse+axis2+tomcat (both create and consume a webservice ) have look on this thread for a similar example

    eclipse+axis2+tomcat

    ReplyDelete
  85. Really a great post man..thanks a lot

    ReplyDelete
  86. Thank you. this is awesome. Now i have to understand what I did and why it worked.

    ReplyDelete
  87. Hi Saranga,

    This is Vinay here.
    Its really great Post and thanks for a lovely explanation. Since i am very new in this web service development, i was hoping if you can help us with a new Database driven Web services in the similar fashion as you have done, would be truly awasome.
    Again thank you very much for all the support!!

    ReplyDelete
  88. Hi ,Sir,It will be thankful if u answer this, i got this error while execeting STEP4: 'jar' is not recognized as an internal or external command,operable program or batch file.

    ReplyDelete
  89. Hi Saranga,

    i have issue on after creating a stub, i cannot write some more service methods. want to build new project every time for overriding the service method. Any other way to solve this problem?

    ReplyDelete
  90. Great tutorial, thank you! That's a great start for learning how to work with web services! Good job!

    ReplyDelete
  91. Great tutorial.. Thank you very much...
    I have created a web service and also generated the .aar file and deployed it in axis2.. but I want a different public URL for this web service... How can I do that???

    ReplyDelete
  92. i've read and seen examples of web service java code decorated with annotations.
    Is this old style, or can you explain when it is to be used?
    or does it apply not to axis?

    thank you

    ReplyDelete
  93. Hi Saranga,

    I am developing Mobile Applications for Android and iPhone. Currently we are using .net platform to create web service through which we are calling required methods for our application.

    The application consists of User authentication...retriveving and storing data and so on.

    we are also writing stored procedures too.

    Please can you provide one simple application/Web service which consists of Java code for creation of web services and stored procedures.

    we are using MS server 2005.

    Regards,
    Indra

    ReplyDelete
  94. i got an error when creating web service client in FirstSoap11BindingStub.java file

    error line
    java.util.Enumeration keys = super.cachedProperties.keys();

    ReplyDelete
  95. nice tutorial man!! thnx :)

    just one problem, how to update stub.java file if i am adding some more methods to web-service class??

    ReplyDelete
  96. very nice tutorial,.. Helped me alot,...Hoping to see some more tutorials from you

    ReplyDelete
  97. I am using apache tomcat 5.5
    axis 1.5.3
    Eclipse
    but i got following error in creating Web Service client..

    "Exception occurred during code generation for WSDL : org.apache.axis2.AxisFault: No operation found in the portType element"


    pls help me ............

    thank u

    ReplyDelete
  98. hi i want to call web service without passing argument,how can i do that

    ReplyDelete
  99. @Admin Thank's for this Tutorial
    But I got error
    Failed while installing Axis2 Web Services Core 1.1.
    java.lang.NullPointerException

    while adding dynamic Project.Please guide me where I am wrong

    ReplyDelete
  100. So, while using this web service, your command prompt should always be open? You can't exit it? because when I close the command prompt, I could not use this web service any more.

    ReplyDelete
  101. hi i have tryed this but .arr from cmd is not working it show acces is denied
    C:\>Users\bronziant\workspace\Divid\WebContent\WEB-INF\services\Hello>jar cvf He
    llo.aar com images META-INF
    Access is denied.

    ReplyDelete
  102. Here is the error while generating the Webservice client:
    Exception occurred while reading or writing files A resource exists with a different case: '/MyFirstWebservice/src/com/Apps'.
    org.eclipse.core.internal.resources.ResourceException: A resource exists with a different case: '/MyFirstWebservice/src/com/Apps'.
    at org.eclipse.core.internal.resources.Resource.checkDoesNotExist(Resource.java:314)
    at org.eclipse.core.internal.resources.Resource.checkDoesNotExist(Resource.java:292)
    at org.eclipse.core.internal.resources.Folder.assertCreateRequirements(Folder.java:30)
    at org.eclipse.core.internal.resources.Folder.create(Folder.java:95)
    at org.eclipse.core.internal.resources.Folder.create(Folder.java:125)
    at org.eclipse.wst.command.internal.env.common.FileResourceUtils.makeFolder(FileResourceUtils.java:575)
    at org.eclipse.wst.command.internal.env.common.FileResourceUtils.makeFolderPathAtLocation(FileResourceUtils.java:812)
    at org.eclipse.wst.command.internal.env.common.FileResourceUtils.makeFolderPathAtLocation(FileResourceUtils.java:833)
    at org.eclipse.jst.ws.axis2.consumption.core.utils.ContentCopyUtils.copyDirectoryRecursivelyIntoWorkspace(ContentCopyUtils.java:104)
    at org.eclipse.jst.ws.axis2.consumption.core.command.Axis2ClientCodegenCommand.execute(Axis2ClientCodegenCommand.java:226)
    at org.eclipse.wst.command.internal.env.core.fragment.CommandFragmentEngine.runCommand(CommandFragmentEngine.java:419)
    at org.eclipse.wst.command.internal.env.core.fragment.CommandFragmentEngine.visitTop(CommandFragmentEngine.java:359)
    at org.eclipse.wst.command.internal.env.core.fragment.CommandFragmentEngine.moveForwardToNextStop(CommandFragmentEngine.java:254)
    at org.eclipse.wst.command.internal.env.ui.widgets.SimpleCommandEngineManager$6.run(SimpleCommandEngineManager.java:294)
    at org.eclipse.jface.operation.ModalContext.runInCurrentThread(ModalContext.java:464)
    at org.eclipse.jface.operation.ModalContext.run(ModalContext.java:372)
    at org.eclipse.jface.wizard.WizardDialog.run(WizardDialog.java:1008)
    at

    ReplyDelete
  103. i followed this tutorial and it works fine.I need to know after i update methods(adding,delete)it doesn't update in .aar file.but when i run in eclips it works fine.how this changes affect to .aar file.

    ReplyDelete
  104. Follwing my code for creating webservice:
    package net.sample;
    import java.sql.Connection;
    import java.sql.DriverManager;
    import java.sql.ResultSet;
    import java.sql.Statement;
    import java.io.BufferedWriter;
    import java.io.File;
    import java.io.FileWriter;

    public class ConnectMSSQL {
    public String get_role(String user1,String password)
    {
    // Create a variable for the connection string.
    String connectionUrl = "jdbc:sqlserver://localhost:1433;" +
    "databaseName=DB_Login;user=sa;password=ftl@123";

    String user2="";
    String password1="";
    try {

    Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
    Connection connection = DriverManager.getConnection(connectionUrl);

    Statement statement = connection.createStatement();
    ResultSet resultSet = statement.executeQuery("SELECT * FROM login_db where
    username='xyz'");
    while ( resultSet.next())
    {

    user2=resultSet.getString("username");
    password1=resultSet.getString("password1");
    }

    } catch (Exception e) {
    e.printStackTrace();

    }
    if(user2.equals("xyz"))
    {
    return "Sucess";
    }
    else
    {
    return "Unsucess";
    }


    }
    }

    Can you plz help me??
    I am not getting any values from db.so its always returning o\p as Unsucess.
    Eventhough values are present in db.
    Can you plz let me no where am wrong???

    ReplyDelete
  105. Hey, I had a great time reading your website. Would you please consider adding a link to my website on your page. Please email me back.

    Regards,

    Angela
    angelabrooks741 gmail.com

    ReplyDelete
  106. If i use CentOS , How can i configure it?

    ReplyDelete
  107. The question I have for you is, How can I access the created web service from a JSP page?

    ReplyDelete
  108. After Long research This is perfect for Beginner :)

    ReplyDelete
  109. Thank you for this detailed article on Web designing course. I’m aspiring to do Web designing course.

    ReplyDelete
  110. Hi ,
    first of all thank you so much for this tutorial.
    i tried to create a new project and my development environment is :
    eclipse mars
    jdk1.8.0_25
    apache-tomcat-8.0.33
    axis2-1.7.1
    i had followed the above steps and while running my webservice i am getting ClassnotFound exceptions.
    SEVERE: StandardWrapper.Throwable
    java.lang.NoClassDefFoundError: org/apache/ws/commons/schema/resolver/URIResolver
    at org.apache.axis2.deployment.ModuleDeployer.deploy(ModuleDeployer.java:128)
    at org.apache.axis2.deployment.repository.util.DeploymentFileData.deploy(DeploymentFileData.java:144)
    at org.apache.axis2.deployment.DeploymentEngine.doDeploy(DeploymentEngine.java:585)
    at org.apache.axis2.deployment.RepositoryListener.init(RepositoryListener.java:264)
    at org.apache.axis2.deployment.RepositoryListener.init2(RepositoryListener.java:66)
    at org.apache.axis2.deployment.RepositoryListener.(RepositoryListener.java:61)
    at org.apache.axis2.deployment.DeploymentEngine.loadRepository(DeploymentEngine.java:152)
    at org.apache.axis2.deployment.WarBasedAxisConfigurator.getAxisConfiguration(WarBasedAxisConfigurator.java:233)
    at org.apache.axis2.context.ConfigurationContextFactory.createConfigurationContext(ConfigurationContextFactory.java:64)
    at org.apache.axis2.transport.http.AxisServlet.initConfigContext(AxisServlet.java:620)
    at org.apache.axis2.transport.http.AxisServlet.init(AxisServlet.java:471)
    at org.apache.axis2.webapp.AxisAdminServlet.init(AxisAdminServlet.java:60)
    at org.apache.catalina.core.StandardWrapper.initServlet(StandardWrapper.java:1238)
    at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1151)
    at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:1038)
    at org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:4996)
    at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5285)
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:147)
    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1408)
    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1398)
    at java.util.concurrent.FutureTask.run(FutureTask.java:266)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
    at java.lang.Thread.run(Thread.java:745)

    please help me to resolve the error

    ReplyDelete
  111. you need to add xmlschema-core-2.2.1.jar (Choose ap[propriate version) and add it to class path and in lib folder

    ReplyDelete
  112. Hi,
    While I'm going to create Client, in the final step I'm stuck with this exception -

    Exception occurred during code generation for WSDL : java.lang.NoClassDefFoundError: org/apache/ws/commons/schema/utils/NamespacePrefixList

    ReplyDelete

Was this information helpful?
Your comments always encourage me to write more, you can post your comment here.

Related Posts Plugin for WordPress, Blogger...