我已经为我们定义的WSDL问题工作了几天。我们使用wsimport从WSDL生成代码,然后使用它来运行服务。在WSImport期间,无法以某种方式解析2个元素,这会引发警告。然而,运行时,这些警告会变成错误,我们无法运行我们的服务。我们如何摆脱这些警告,从而摆脱错误?
非常感谢所有指针。
我们正在使用Metro 2.3和Java 7.
WSDL正在使用HR-XML规范中的xsds,但我将它们修剪下来以更清楚地显示问题。
wsimport报道:
MacBook-Pro-van-Martin:WSDL-problem sunsear$ wsimport -Xnocompile -s generated "file:DummyService.wsdl"
parsing WSDL...
[WARNING] src-resolve: Cannot resolve the name 'hr:Assignment' to a(n) 'element declaration' component.
line 14 of file:xsd/AssignmentRequestElement.xsd
[WARNING] src-resolve: Cannot resolve the name 'hr:HumanResource' to a(n) 'element declaration' component.
line 15 of file:xsd/AssignmentRequestElement.xsd
Generating code...
WSimport抱怨hr:Assignment和hr:HumanResource在AssignmentRequestElement.xsd中引用:
<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema xmlns="http://personnel.services.com/services/2013-10"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:hr="http://ns.hr-xml.org/2007-04-15"
targetNamespace="http://personnel.services.com/services/2013-10"
elementFormDefault="qualified" version="2013-10">
<xsd:import namespace="http://ns.hr-xml.org/2007-04-15" schemaLocation="HR-XML-2_5/SIDES/Assignment.xsd"/>
<xsd:import namespace="http://ns.hr-xml.org/2007-04-15" schemaLocation="HR-XML-2_5/SIDES/HumanResource.xsd"/>
<xsd:element name="AssignmentRequestElement">
<xsd:complexType>
<xsd:sequence>
<xsd:element ref="hr:Assignment"/>
<xsd:element ref="hr:HumanResource" minOccurs="0"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</xsd:schema>
HumanResource看起来像这样:
<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://ns.hr-xml.org/2007-04-15"
targetNamespace="http://ns.hr-xml.org/2007-04-15" elementFormDefault="qualified" version="2007-04-15">
<xsd:complexType name="HumanResourceType">
<xsd:sequence>
<xsd:element name="HumanResourceId" type="xsd:string" maxOccurs="unbounded"/>
</xsd:sequence>
</xsd:complexType>
<xsd:element name="HumanResource" type="HumanResourceType"/>
</xsd:schema>
作业如下:
<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema xmlns="http://ns.hr-xml.org/2007-04-15" xmlns:xsd="http://www.w3.org/2001/XMLSchema" targetNamespace="http://ns.hr-xml.org/2007-04-15" elementFormDefault="qualified" version="2007-04-15">
<xsd:complexType name="AssignmentType">
<xsd:sequence>
<xsd:element name="AssignmentId" type="xsd:string" maxOccurs="unbounded"/>
</xsd:sequence>
</xsd:complexType>
<xsd:element name="Assignment" type="AssignmentType"/>
</xsd:schema>
为了完整性,这是WSDL本身:
<?xml version="1.0" encoding="UTF-8"?>
<wsdl:definitions xmlns:tns="http://personnel.services.com/services/2013-10"
xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
xmlns:hr="http://ns.hr-xml.org/2007-04-15" xmlns:wsdlsoap="http://schemas.xmlsoap.org/wsdl/soap/"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://personnel.services.com/services/2013-10">
<wsdl:types>
<xsd:schema
elementFormDefault="qualified">
<xsd:import namespace="http://ns.hr-xml.org/2007-04-15"
schemaLocation="xsd/HR-XML-2_5/CPO/Acknowledgement.xsd"/>
<xsd:import namespace="http://personnel.services.com/services/2013-10"
schemaLocation="xsd/AssignmentRequestElement.xsd"/>
</xsd:schema>
</wsdl:types>
<wsdl:message name="AssignmentRequest">
<wsdl:documentation>A generic request of type Assignment (A) or Assignment+HumanResource (A+HR).
</wsdl:documentation>
<wsdl:part name="input" element="tns:AssignmentRequestElement"/>
</wsdl:message>
<wsdl:message name="Response">
<wsdl:documentation>A generic response of type Acknowledgement.</wsdl:documentation>
<wsdl:part name="output" element="hr:Acknowledgement"/>
</wsdl:message>
<wsdl:portType name="DummyService">
<wsdl:operation name="ProcessAssignment">
<wsdl:documentation>ProcessAssignment is used to send details of an Assignment
The request message is an Assignment (A) or
an Assignment+HumanResource (A+HR) message.
</wsdl:documentation>
<wsdl:input message="tns:AssignmentRequest"/>
<wsdl:output message="tns:Response"/>
</wsdl:operation>
</wsdl:portType>
<wsdl:binding name="SoapServiceHttpBinding" type="tns:DummyService">
<wsdlsoap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
<wsdl:operation name="ProcessAssignment">
<wsdlsoap:operation soapAction="https://dummy.personnel.services.com/ws/DummySoapService/ProcessAssignment"
style="document"/>
<wsdl:input>
<wsdlsoap:body use="literal"/>
</wsdl:input>
<wsdl:output>
<wsdlsoap:body use="literal"/>
</wsdl:output>
</wsdl:operation>
</wsdl:binding>
<wsdl:service name="DummySoapService">
<wsdl:port name="DummyServicesEndpoint" binding="tns:SoapServiceHttpBinding">
<wsdlsoap:address location="https://dummy.personnel.services.com/ws/DummySoapService"/>
</wsdl:port>
</wsdl:service>
</wsdl:definitions>
根据SoapUI和XMLSpy,WSDL和XSD是正确的,它们可以正确验证消息。
可以在此处下载wsdl和xsds:
答案 0 :(得分:3)
您已为同一名称空间网址分配了2个不同的架构位置。这可能是造成此错误的原因,因为现在wsimport不知道在哪里搜索hr:objects。
<xsd:import namespace="http://ns.hr-xml.org/2007-04-15" schemaLocation="HR-XML-2_5/SIDES/Assignment.xsd"/>
<xsd:import namespace="http://ns.hr-xml.org/2007-04-15" schemaLocation="HR-XML-2_5/SIDES/HumanResource.xsd"/>
看看这个stackoverflow问题来解决这个问题: SAXParseException; src-resolve: Cannot resolve the name '...' to a(n) 'type definition' component