如何编写Java客户端来访问WSDL文件? [英] How to write a Java client to access WSDL file?
问题描述
如何使用Java访问 .wsdl
文件中的公开方法?此外,编写Java客户端和使用Web服务涉及哪些步骤?
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?
推荐答案
除了精英绅士的回答,这是我的步骤我成功用于生成类以便能够使用webservice:
命令:
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
说明:
- ' - Xnocompile'禁止生成.class文件
- ' - keep'确保生成的Java文件不会被删除(默认情况下,仅限.class文件仍然存在)
- ' - b'指定绑定配置文件。这是必要的! (见下文)
我遇到的问题是Java类包含 JAXBElement< Type>
包装类。
因此,我会得到 String
类型的类成员,我会得到类型 JAXBElement< String>
,这是可怕的使用。使用 -b
切换 wsimport
以及以下 binding.xml
文件,你得到正确的类型:
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>
我希望这会有所帮助。 wsimport
然后生成所需的所有类以及包含所有webservices方法的方法的类。
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.
这篇关于如何编写Java客户端来访问WSDL文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!