I have been given a WSDL file and I need to consume a web service using this WSDL file over the internet. I need to do this in Jav开发者_如何学Pythona.
Could someone tell me the steps for doing this? I would also appreciate some useful links.
I'd use JAX-WS (please, please, forget Axis or Axis 2, see previous answers) and the good news is that Java 6 includes JAX-WS RI so you already have everything required, nothing to do. In other words, just use wsimport
to generate the classes required to call the web service.
Example:
wsimport -p stockquote http://stockquote.xyz/quote?wsdl
This will generate the Java artifacts and compile them by importing the http://stockquote.xyz/quote?wsdl.
Invoking the web service is then a matter of three lines of code (without including the initialization of WS arguments). See Creating a Simple Web Service and Client with JAX-WS in the Java EE tutorial, Getting Started with JAX-WS Web Services or Developing JAX-WS Web Service Clients for examples.
The first step is to generate classes that can speak to this webservice. Take a look at open source solutions such as Axis2. This will generate stubs for you to talk to the webservice in code... then it's all up to you to use this service.
It would be helpful if you are using an IDE. For instance, in Netbeans you can follow this tutorial and do what you ask quite easily. It is similarly easy in Eclipse.
Here is an Eclipse plugin for Axis (Mentioned in other answers).
I haven't done this in Java in yeeeeears, but what I did that many years ago was use a command line tool called Axis (I believe the actual command was wsdl2java). You run the command passing in the url to your wsdl as an argument, and it will generate the proxy classes that you can use in your app.
You should do a little research on this as opposed to just getting a spoon-fed solution, but basically you'll most likely end up with some kind of tool that will automatically generate classes for you. You use these classes to interact with the service so that essentially you don't even have to know you're interacting with a service at all.
There is a command line tool called "wsimport" bundled with your jdk (if you use 1.6, not sure about the version though). It's similiar to wsdl2java from Apache Axis, but it generates way cleaner code (imho).
精彩评论