0

I have been workin in java for a while, the project which i'm doing now requires to get data from a web service(Well i have never worked in web services befor :D). I have a wsdl file and also the link for the wsdl file. I wanted to know how to call the webservice in my java program with the input variables to the web service.

Thank you in advance.

user1743673
  • 99
  • 2
  • 3
  • 11

3 Answers3

1

You can generate your web service client classes using jaxws utilities and the published wsdl

e.g.

something like

wsimport -target 2.2 -s C:\temp\outputcode -p com.package.name http://1.2.3.4/jaxsws/wsname?wsdl

This will put classes into C:\temp\outputcode that you can use in your project.

Look for a class extending Service. This will have a number of constructors that allow the WSDL location to be overridden.

From the Service you obtain a handle (proxy) to the web service Port. (This will be a generated Interface with methods corresponding to web service methods in the wsdl). You then invoke the method and this will call the web service.

There is some further information here How does a wsimport generated client work?

Community
  • 1
  • 1
shonky linux user
  • 6,131
  • 4
  • 46
  • 73
  • I have alreay saved the wsdl in my local system. SO, can i use the same wsdl in my java program, like specifing the path in my progrma ?? – user1743673 Aug 09 '13 at 02:08
  • Yes, the generated service class will have a number of constructors, some of which will allow you to override the URL to the WSDL (which can be local to your java program). – shonky linux user Aug 09 '13 at 02:10
  • Thank you for your reply. Can you let me know any tutorials or links whihc can give me more info about this. – user1743673 Aug 09 '13 at 02:44
0

You can also use the axis wsdl2java aswell download the axis2 and you can use wsdl2java tool and pass ur wsdl file path/url it will generate the client side artifacts (java stubs) and you can use these stubs to call the required webservice

(But before jumping into it, i would suggest u to dig-in more abt webservices and wsdl and you can also test the web services quickly using the Soapui(which consumes wsdl) that will clarify whether web service is returning what ur looking for)

chaos..

Prashant
  • 81
  • 1
  • 3
  • Basic Web Service client generation using wsimport comes with the JDK whereas axis2 requires additional library downloads and setup / configuration, i.e. complexity. It would be simpler for OP to stick to native jdk provided tools to start out with. – shonky linux user Aug 12 '13 at 06:53
  • refer also http://stackoverflow.com/questions/3588616/java-webservice-client-best-way/3590252#3590252 before touching Axis2. – shonky linux user Aug 12 '13 at 07:00
0

There's some really great IDEs that does the job easily. Try to look at Netbeans or IntelliJ IDEA.

Davmrtl
  • 178
  • 1
  • 1
  • 7