tags:

views:

137

answers:

5

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 jave ...could someone tell me the steps for doing this..i would also appreciate some useful links...

+3  A: 

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.

Malaxeur
When will people realize that Axis sucks like hell?
Pascal Thivent
I've used it once in my life and hopefully never again :P It's just the first example that came to mind.
Malaxeur
A: 

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.

Rich
A: 

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).

Vincent Ramdhanie
A: 

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).

Willi
+1  A: 

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.

Pascal Thivent