Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to write a Java client to access WSDL file?

How can I access the exposed methods in a .wsdl file using Java? Also, what are the steps involved in writing a Java client and consuming the webservices?

like image 589
sarah Avatar asked Aug 16 '10 10:08

sarah


People also ask

How do I create a WSDL client in Java?

Generate the client code as follows: In the Project Explorer, right-click your client project's WSDL file, and then select WebLogic Web Services > Generate Web Service Client from the drop-down menu, as Figure 1 shows. This will open the New Web Service Client dialog that Figure 2 shows.


1 Answers

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">
    <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 don't have a read timeout (talking network problems while requesting...), see here for a question I had back then.

like image 156
f1sh Avatar answered Sep 24 '22 04:09

f1sh