如何在 Java 中解析 WSDL?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2495740/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-29 21:28:57  来源:igfitidea点击:

How to parse WSDL in Java?

javaweb-serviceswsdl

提问by Milan

I need parser for WSDL to get the messages, portTypes, operations, bindings, services,... I hope some parser already exists. So, any guidlines?

我需要 WSDL 的解析器来获取消息、端口类型、操作、绑定、服务……我希望一些解析器已经存在。那么,任何指导方针?

回答by R K

Hope this link will be useful for you to choose a WSDL parser, Parse WSDL Effectively(look at the archive of this Link: Web Archive).

希望此链接对您选择 WSDL 解析器有用,Parse WSDL Effectively(查看此链接的存档:)Web Archive

I have tried using Apache Woden, WSDL4Jand Membrane SOA. Apache Woden or Membrane SOA would do fine.

我曾尝试使用Apache Woden,WSDL4JMembrane SOA. Apache Woden 或 Membrane SOA 都可以。

回答by sreehari

f wsdl = '''
<definitions name="AgencyManagementService"
    xmlns:ns1="http://www.example.org/NS1"
    xmlns:ns2="http://www.example.org/NS2">
    <ns1:message name="SomeRequest">
        <ns1:part name="parameters" element="SomeReq" />
    </ns1:message>
    <ns2:message name="SomeRequest">
        <ns2:part name="parameters" element="SomeReq" />
    </ns2:message>
</definitions>
'''

def xml = new XmlSlurper().parseText(wsdl).declareNamespace(ns1: 'http://www.example.org/NS1', ns2: 'http://www.example.org/NS2')
println xml.'ns1:message'.'ns1:part'.size()
println xml.'ns2:message'.'ns2:part'.size()

Hope this helps. Groovy class can be called from any other Java class. Move all XML labor to Groovy :)

希望这可以帮助。Groovy 类可以从任何其他 Java 类中调用。将所有 XML 劳动力转移到 Groovy :)

回答by max.shmidov

Have a look at wsimporttool documentation at http://docs.oracle.com/javase/6/docs/technotes/tools/share/wsimport.html. It is a standard JDK tool that generates JAXB-based Java artifacts for interactions with web service.

wsimporthttp://docs.oracle.com/javase/6/docs/technotes/tools/share/wsimport.html查看工具文档 。它是一个标准的 JDK 工具,可生成基于 JAXB 的 Java 工件以与 Web 服务交互。

回答by youhans

you can use membrane-soa for parsing wsdl files. add dependency from http://mvnrepository.com/artifact/com.predic8/soa-model-core.

您可以使用membrane-soa 来解析wsdl 文件。从http://mvnrepository.com/artifact/com.predic8/soa-model-core添加依赖项。

you can find documantation at http://membrane-soa.org/soa-model/.

您可以在http://membrane-soa.org/soa-model/找到文档。

回答by Thorbj?rn Ravn Andersen

Several Web Service stacks are available.

有几个 Web 服务堆栈可用。

Have a look at the Metro stack. Open Source and available directly in Java 6.

看看 Metro 堆栈。开源并直接在 Java 6 中可用。

回答by Santhosh Kumar Tekuri

use http://sourceforge.net/projects/wsdl4j/

使用http://sourceforge.net/projects/wsdl4j/

public Definition readWSDLFile(String location) throws  WSDLException {
    WSDLReader reader = getWsdlFactoryInstance().newWSDLReader();
    reader.setFeature("javax.wsdl.importDocuments", true);
    return reader.readWSDL(location);
}