views:

176

answers:

5

Hi All,

I have a .wsdl file i need to access the exposed method in it using java,how can i do it,i am new to webservices so not getting it what are the steps involved to write a java client and consume the webservices ,pLease let me know

+1  A: 

I would recommend starting with the Web Service Explorer in Eclipse JEE. This allows you to investigate any web service given the WSDL.

The instructions to convert the WSDL to Java depends on which web service library you want to use. If you use Java 6 the Metro stack is built in.

Thorbjørn Ravn Andersen
+3  A: 

You will need to need to generate a Java proxy from the WSDL File. You can do this by using Apche CXF or Apache Axis/Axis2 to generate Java Proxy/Java Client.

In Java 6, you can also generate java client too. On the JDK/bin there's wsimport to generate Web Service client or in Axis, there's WSDL2Java that does the same thing like wsimport.

The Elite Gentleman
How to use the wsipmort.exe file ?
sarah
Click on the link on `wsimport` and there's solution for it.
The Elite Gentleman
+1  A: 

In addition to The Elite Gentleman's answer, here are my steps I successfully used to generate classes to be able to use the webservice: Command:

wsimport -Xnocompile -keep -b binding.xml wsdlFile.wsdl

Explanation:

  • '-Xnocompile' suppresses the generation of .class files
  • '-keep' makes sure the generated java files wont be deleted (by default, only the .class files remain)
  • '-b ' specifies a binding configuration file. This is necessary! (see below)

I had the problem that the java classes contained the JAXBElement<Type> wrapper classes. So instead of a class member of type String, I would get the type JAXBElement<String>, which is horrible to use. With the -b switch for wsimport and the following binding.xml file, you get the correct types:

<jaxb:bindings version="2.0"
  xmlns:jaxb="http://java.sun.com/xml/ns/jaxb"
  xmlns:xs="http://www.w3.org/2001/XMLSchema"&gt;
    <jaxb:bindings>
        <jaxb:globalBindings generateElementProperty="false" />
    </jaxb:bindings>
</jaxb:bindings>

I hope this helps. wsimport then generates all the classes you need as well as a class containing methods for all your webservices' methods.

By default, these methods dont have a read timeout (talking network problems while requesting...), see here for a question I had back then.

f1sh
+1  A: 

I would take a look at getting your IDE to automatically generate everything.

In Netbeans, the steps are:

Right Click on your project, click "add Web Service Client", enter the WDSL url and click Finish.

This will auto-magically create the Java proxy for you.

To implement the client in your code, drag and drog the required method (located in Web Services References in your project), into your code.

vicjugador
+1 I was just about going to recommend it. NetBeans in this case make it trivial.
Rekin
A: 

soapUI is one of the softwares allowing you to easily get into WSDL / SOAP world. You can generate SOAP requests with test values to be sent to the server. You can also see the server's SOAP responses. This will let you understand a bit more of WSDL / SOAP. For generating the java code from the wsdl see the recommendations above.

D_K