我有几个SOAP服务(在.Net中实现),我想为它们生成Java存根。第一个服务没有问题,但第二个服务抛出错误
WSDLToJava Error:
http://localhost/AMS52/ServiceManagement.svc?xsd=xsd8 [0,0]: Two declarations cause a collision in the ObjectFactory class.
http://localhost/AMS52/ServiceManagement.svc?xsd=xsd11 [0,0]: (Related to above error) This is the other declaration.
由于不太熟悉这些东西,我最终发现wsdl中的两个导入正在互相踩
<wsdl:types>
<xsd:schema targetNamespace="http://tempuri.org/Imports">
...
<xsd:import schemaLocation="http://localhost/AMS52/ServiceManagement.svc?xsd=xsd8" namespace="http://schemas.datacontract.org/2004/07/Company.Platform.Datatypes.Enums"/>
...
<xsd:import schemaLocation="http://localhost/AMS52/ServiceManagement.svc?xsd=xsd11" namespace="http://schemas.datacontract.org/2004/07/Company.Platform.Datatypes.ServiceManagement"/>
...
第一个导入的xsd的形式为
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:tns="http://schemas.datacontract.org/2004/07/Company.Platform.Datatypes.Enums"
elementFormDefault="qualified"
targetNamespace="http://schemas.datacontract.org/2004/07/Company.Platform.Datatypes.Enums">
<xs:simpleType name="DeviceIdiom">
<xs:restriction base="xs:string">
<xs:enumeration value="Auto"/>
<xs:enumeration value="Phone"/>
<xs:enumeration value="Tablet"/>
</xs:restriction>
</xs:simpleType>
<xs:element name="DeviceIdiom" nillable="true" type="tns:DeviceIdiom"/>
<xs:simpleType name="ServiceManagementSORType">
...
更多的阅读,我发现我必须做一些类似的事情
如何解决wsdl2java上ObjectFactory中的冲突?
因此,我的方法是尝试在每个简单类型的末尾加一个后缀(它们都是简单类型)。
所以我现在的命令行是
./wsdl2java.bat -impl -server -verbose -autoNameResolution -b bindings.xml ServiceManagement.wsdl
我的绑定文件是
<jaxb:bindings
xmlns:jaxb="http://java.sun.com/xml/ns/jaxb"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
jaxb:version="2.1">
<jaxb:bindings schemalocation="http://localhost/AMS52/ServiceManagement.svc?xsd=xsd8" node="/xs:schema">
<jaxb:bindings node="//xs:simpleType">
<jaxb:nameXmlTransform>
<jaxb:typeName suffix="Enums" />
</jaxb:nameXmlTransform>
</jaxb:bindings>
</jaxb:bindings>
</jaxb:bindings>
但现在我被这个错误卡住了
XPath evaluation of "//xs:schema" results in empty target node
我不知道如何克服这个错误。我开始认为这与它是一个.Net服务有关,并且我必须引用xsd这样的
http://localhost/AMS52/ServiceManagement.svc?xsd=xsd8
非常感谢您的帮助。
终于想通了,我更换了
<jaxb:bindings schemalocation="http://localhost/AMS52/ServiceManagement.svc?xsd=xsd8" node="/xs:schema">
带有
<jaxb:bindings schemaLocation="http://localhost/AMS52/ServiceManagement.svc?xsd=xsd8" node="/xs:schema">
不容易看到,但请注意schemaLocation中的大写字母L-哎哟!
通过使用绑定文件将"Company.Platform.Datatypes.Enums"的架构映射到另一个包,最终解决了整个问题
<jaxb:bindings
xmlns:jaxb="http://java.sun.com/xml/ns/jaxb"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
jaxb:version="2.1">
<jaxb:bindings schemaLocation="http://localhost/AMS52/ServiceManagement.svc?xsd=xsd8">
<jaxb:schemaBindings>
<jaxb:package name="org.tempuri.enums"/>
</jaxb:schemaBindings>
</jaxb:bindings>