Java JAX WS 生成的 WSDL 与 wsgen
Java JAX WS generated WSDL vs wsgen
我在 java 中有一个 JAX WS Web 服务,我将其从类型 Document 更改为 RPC下一行:
@SOAPBinding(style = Style.RPC)
问题是当我尝试使用 JDK 1.8 中的 wsgen.exe(版本 2.2.9)时。0_91:
"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>
但是URLhttp://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?
最后我发现WSDL是用CXF生成的,因为wsgen工具使用的是默认的JAXB实现,而这个不会转换接口如List<>
和类如ArrayList<>
像我之前提到的那样通过以下方式转换:
<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。
我在 java 中有一个 JAX WS Web 服务,我将其从类型 Document 更改为 RPC下一行:
@SOAPBinding(style = Style.RPC)
问题是当我尝试使用 JDK 1.8 中的 wsgen.exe(版本 2.2.9)时。0_91:
"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>
但是URLhttp://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?
最后我发现WSDL是用CXF生成的,因为wsgen工具使用的是默认的JAXB实现,而这个不会转换接口如List<>
和类如ArrayList<>
像我之前提到的那样通过以下方式转换:
<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。