Thursday, July 25, 2013

Java WebService Tutorial - Part 06 ( Using wsimport tool to generate Client and accessing a Webservice )


In this tutorial we will see how wsimport tool can be used to generate java classes from a wsdl and how we can access a webservice easily like normal java applications.

wsimport :

This tool is come along with the jdk.If you have install the JDK properly and your classpath or JAVA_HOME variable is set you can see the list of options provided by this command  by typing wsimport in the command prompt.

For generating Java classess from wsimport the syntax is :

wsimport  wsdl-location-path  -d -keep

The wsdl-location-path : Is the location of wsdl file existence.

-d : specify the directory where all the generated classes should be placed.

-keep : It will keep the java source code of generated classes in the respective directory mentioned.

-extension :allow vendor extension - functionality if not have been specified.

Ex:

wsimport  hello.wsdl   src  -keep

Now we will take the sample webservice of w3schools which has the follwing wsdl location:

http://www.w3schools.com/webservices/tempconvert.asmx?WSDL

Execute the command in DOS Prompt to generate classes from wsdl :

 C:\webservice> wsimport  http://www.w3schools.com/webservices/tempconvert.asmx?WSDL -extension   -keep
 


















After execution it will create a folder called org inside the webs service folder.

Now Create a Main class to access these webservice :

 Code:

import org.tempuri.*;

 public class Main {
   
    public static void main(String a[])
    {
        TempConvert convert=new TempConvert();
        System.out.println(convert.getTempConvertSoap().celsiusToFahrenheit("122"));
       
    }
}
   
Save these class inside "webservice" folder .Compile and run it you will see the output as "251.6" returning from web service.

Result :















<<Prev          Index            Next >>                 

 -------------------------------------------------------





Technology Blogs
blogs

37 comments:

  1. Not working error:

    Exception in thread "main" java.lang.NoClassDefFoundError: Main (wrong name: com/w3schools/webservices/Main)
    at java.lang.ClassLoader.defineClass1(Native Method)
    at java.lang.ClassLoader.defineClass(Unknown Source)
    at java.security.SecureClassLoader.defineClass(Unknown Source)
    at java.net.URLClassLoader.defineClass(Unknown Source)
    at java.net.URLClassLoader.access$100(Unknown Source)
    at java.net.URLClassLoader$1.run(Unknown Source)
    at java.net.URLClassLoader$1.run(Unknown Source)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at sun.launcher.LauncherHelper.checkAndLoadMain(Unknown Source)

    ReplyDelete
  2. Hi there everyone, it's my first visit at this site, and piece of writing is in fact fruitful for me, keep up
    posting these articles.

    My webpage Beats By Dre UK

    ReplyDelete
  3. It's impressive that you are getting thoughts from this article as well as from our argument made
    here.

    Feel free to visit my blog post :: Dre Headphones

    ReplyDelete
  4. Hello! I know this is kind of off topic but I was wondering if you knew where I could find a captcha plugin for my comment form?
    I'm using the same blog platform as yours and I'm having problems finding one?
    Thanks a lot!

    My blog post - Running Shoes

    ReplyDelete
  5. Heya i am for the first time here. I came across this board and I find
    It truly useful & it helped me out a lot. I hope to give something back and aid others like you
    helped me.

    Feel free to surf to my website: New Balance
    Discount (foro.guerramutante.es)

    ReplyDelete
  6. It's difficult to find educated people about this topic, but you sound
    like you know what you're talking about! Thanks

    Check out my webpage ... Fake Louis Vuitton Bags

    ReplyDelete
  7. I really like looking through an article that will make people think.
    Also, thanks for allowing for me to comment!


    my web blog - Christian Louboutin Boots

    ReplyDelete
  8. Hi, i think that i saw you visited my website so i came to “return the favor”.I'm trying to find
    things to enhance my website!I suppose its ok to use
    a few of your ideas!!

    My web page - New Balance Shoes

    ReplyDelete
  9. Hey There. I discovered your weblog the use of
    msn. That is a really neatly written article.
    I will make sure to bookmark it and come back to read more of
    your helpful info. Thanks for the post. I will definitely return.

    Take a look at my page ... New Balance Minimus

    ReplyDelete
  10. Getting below mentioned error:

    D:\IBM\SDP\runtimes\base_v7\bin>wsimport http://www.w3schools.com/webservices/t
    empconvert.asmx?WSDL -extension -keep
    parsing WSDL...


    [ERROR] Failed to read the WSDL document: http://www.w3schools.com/webservices/t
    empconvert.asmx?WSDL, because 1) could not find the document; /2) the document c
    ould not be read; 3) the root element of the document is not .

    unknown location

    Failed to parse the WSDL.

    kindly help to resolve the issue

    ReplyDelete
  11. Can you provide small example for wsimport JAXB option -b/-B

    ReplyDelete
  12. This tool http://fastthread.io/ is faster and easier for analyzing thread dumps, which might actually be worth trying.

    ReplyDelete
  13. Thank you for your precious information. very clear explanation.Please share more like that..
    Automotive erp software in chennai

    ReplyDelete
  14. This is a nice article here with some useful tips for those who are not used-to comment that frequently. Thanks for this helpful information I agree with all points you have given to us. I will follow all of them.
    Devops Training courses
    python Training in chennai
    Devops Training in Bangalore

    ReplyDelete
  15. I appreciate that you produced this wonderful article to help us get more knowledge about this topic.
    I know, it is not an easy task to write such a big article in one day, I've tried that and I've failed. But, here you are, trying the big task and finishing it off and getting good comments and ratings. That is one hell of a job done!

    Selenium training in bangalore
    Selenium training in Chennai
    Selenium training in Bangalore
    Selenium training in Pune
    Selenium Online training
    Selenium interview questions and answers

    ReplyDelete
  16. I am sure this post has helped me save many hours of browsing other related posts just to find what I was looking for. Many thanks!
    Python Online training
    python Course institute in Chennai
    Python Course institute in Bangalore

    ReplyDelete
  17. Such a great information for blogger iam a professional blogger thanks…

    Upgrade your career Learn Oracle Training from industry experts gets complete hands on Training, Interview preparation, and Job Assistance at Softgen Infotech.

    ReplyDelete
  18. Computer Full Form is very usefull in students for study in education

    ReplyDelete
  19. E shram Card is a labor registration portal created by the Labor Department, Government of india.

    ReplyDelete
  20. KGF 2 : Directed by Prashanth Neel. With Yash, Sanjay Dutt, Raveena Tandon, Prakash Raj. The blood-soaked land of Kolar Gold Fields

    ReplyDelete
  21. All type services start in Bihar Govt go to see this services and help for filling form RTPS Bihar

    ReplyDelete
  22. Welcome to CapturedCurrentNews – Latest & Breaking India News 2021
    Hello Friends My Name Anthony Morris.latest and breaking news drupepower.com

    ReplyDelete
  23. I really enjoy the article.Thanks Again. Fantastic.
    net coure
    net training

    ReplyDelete
  24. These are very good post and i like your post...hindi skill

    ReplyDelete
  25. Step-by-Step Hacking Tutorials about WiFi hacking,
    Kali Linux, Metasploit, exploits, ethical hacking, information security, malware analysis and scanning
    hacking

    ReplyDelete
  26. Something probably home region a beyond strategy. Once bank recently program rate behavior. Over decade society fast movement. Executive each field traditional think style own.entertainment

    ReplyDelete
  27. As soldier security section history. Thought force ability four I time. Probably claim picture pretty activity window situation individual.career-news

    ReplyDelete