【问题标题】:Java JAX WS generated WSDL vs wsgenJava JAX WS 生成的 WSDL 与 wsgen
【发布时间】:2016-11-05 15:32:37
【问题描述】:

我在 java 中有一个 JAX WS Web 服务,我将它从 Document 类型更改为 RPC 并使用以下行:

@SOAPBinding(style = Style.RPC)

问题是当我尝试使用 JDK 1.8.0_91 中的 wsgen.exe(版本 2.2.9)时:

"C:\Program Files\Java\jdk1.8.0_91\bin\wsgen.exe" -verbose -cp . com.ws.ServiceImpl -wsdl -inlineSchemas

insertDevolutions 方法生成的 WSDL 如下:

<xs:schema version="1.0" targetNamespace="..." xmlns:xs="http://www.w3.org/2001/XMLSchema">      
    <xs:complexType name="arrayList">
        <xs:complexContent>
            <xs:extension base="tns:abstractList">
                <xs:sequence/>
            </xs:extension>
        </xs:complexContent>
    </xs:complexType>
    <xs:complexType name="abstractList" abstract="true">
        <xs:complexContent>
            <xs:extension base="tns:abstractCollection">
                <xs:sequence/>
            </xs:extension>
        </xs:complexContent>
    </xs:complexType>
    <xs:complexType name="abstractCollection" abstract="true">
        <xs:sequence/>
    </xs:complexType>
</xs:schema>
 ...
<message name="insertDevolutions">
    <part name="arg0" type="xsd:string"/>
    <part name="arg1" type="tns:arrayList"/>
    <part name="arg2" type="xsd:string"/>
    <part name="arg3" type="xsd:string"/>
    <part name="arg4" type="xsd:string"/>
    <part name="arg5" type="xsd:string"/>
    <part name="arg6" type="xsd:boolean"/>
</message>

但是服务生成的 URL http://localhost:8080/TestWS/ServiceImpl?wsdl 的 WSDL 完全不同,因为对象 devolution 生成正确:

<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:tns="..." attributeFormDefault="unqualified" elementFormDefault="unqualified" targetNamespace="...">
    <xs:complexType name="devolution">
        <xs:sequence>
            <xs:element name="company" type="xs:string"/>
            <xs:element name="currency" type="xs:string"/>
            <xs:element name="registerDate" type="xs:dateTime"/>>
            <xs:element name="total" type="xs:double"/>
        </xs:sequence>
    </xs:complexType>
    <xs:complexType final="#all" name="devolutionArray">
        <xs:sequence>
            <xs:element maxOccurs="unbounded" minOccurs="0" name="item" nillable="true" type="tns:devolution"/>
        </xs:sequence>
    </xs:complexType>
</xs:schema>
...
<wsdl:message name="insertDevolutions">
    <wsdl:part name="arg0" type="xsd:string"/>
    <wsdl:part name="arg1" type="tns:devolutionArray"/>
    <wsdl:part name="arg2" type="xsd:string"/>
    <wsdl:part name="arg3" type="xsd:string"/>
    <wsdl:part name="arg4" type="xsd:string"/>
    <wsdl:part name="arg5" type="xsd:string"/>
    <wsdl:part name="arg6" type="xsd:boolean"/>
</wsdl:message>

所以我想知道 URL 中带有 wsdl 选项的 WSDL 是如何生成的,因为我认为 JAX WS 使用与 wsgen 相同的工具。是否有其他工具可以像服务提供的那样生成 WSDL?

【问题讨论】:

  • 你使用哪个容器?

标签: java web-services wsdl jax-rs wsgen


【解决方案1】:

最后我发现 WSDL 是用 CXF 生成的,因为工具 wsgen 使用默认的 JAXB 实现,而这个工具不会转换像 List&lt;&gt; 这样的接口,而像 ArrayList&lt;&gt; 这样的类会像我之前在下面提到的那样进行转换方式:

<xs:complexType name="arrayList">
    <xs:complexContent>
        <xs:extension base="tns:abstractList">
            <xs:sequence/>
        </xs:extension>
    </xs:complexContent>
</xs:complexType>

所以当我使用 CXF 提供的工具和以下命令时:

"C:\apache-cxf-3.1.6\bin\java2ws" -wsdl -d . com.ws.ServiceImpl

RPC 样式的 WSDL 已正确生成。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-11-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多