【发布时间】:2014-01-21 06:10:30
【问题描述】:
几天来,我一直在解决我们定义的 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 抱怨在 AssignmentRequestElement.xsd 中引用的 hr:Assignment 和 hr:HumanResource:
<?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>
人力资源看起来像这样:
<?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 可以在这里下载:
【问题讨论】:
-
哎呀,继续前进,似乎导入完成的顺序对于 wsimport 理解 WSDL 至关重要。
-
我在wsimport期间也有很多警告,但是这些警告没有出现任何问题。这些警告如何变成错误?什么验证这些文件 Eclipse、服务器等?
-
我们使用从 wsimport 生成的类与 Metro 运行时一起运行。它从 Generated 类动态生成 WSDL。该 WSDL 与原始 WSDL 不同,并导致元素更改名称空间,这是不正确的。当我们使用原始 WSDL 而不是重新生成的 WSDL 时,Metro 运行时会在启动时验证 WSDL,但无法正确解析它,从而给出与 wsimport 作为警告抛出的完全相同的错误。然后它无法正确启动。
标签: java web-services wsdl wsimport java-metro-framework