How to write a Java client to access WSDL file?

后端 未结 7 1052
春和景丽
春和景丽 2020-12-17 03:16

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?

7条回答
  •  -上瘾入骨i
    2020-12-17 03:39

    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 wrapper classes. So instead of a class member of type String, I would get the type JAXBElement, which is horrible to use. With the -b switch for wsimport and the following binding.xml file, you get the correct types:

    
        
            
        
    
    

    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.

提交回复
热议问题