【发布时间】:2014-03-20 14:26:26
【问题描述】:
我有两个 WSDL 文件。 我正在尝试在 complexType 元素内的另一个 WSDL 文件中使用一个 WSDL 类型中定义的元素。
为此,我使用导入元素包含了另一个 WSDL 文件(otherfile.wsdl 位于同一文件夹中)。 此外,我设置了命名空间并使用 ref 属性(加上命名空间)来引用其他 WSDL 文件中的元素。
但是,它抱怨来自 othertest 命名空间的元素不能从此 test.wsdl xml 模式中引用。 有人知道如何解决这个问题吗?
您将在下面找到这两个文件的代码:
test.wsdl
<definitions xmlns="http://schemas.xmlsoap.org/wsdl/"
xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
xmlns:http="http://schemas.xmlsoap.org/wsdl/http/"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:tns="http://www.example.com/test/"
xmlns:ot="http://www.example.com/othertest/"
targetNamespace="http://www.example.com/test/" >
<import namespace="http://www.example.com/othertest/" location="othertest.wsdl"/>
<types>
<xsd:schema targetNamespace="http://www.example.com/test/">
<xsd:element name="ResultElement2">
<xsd:complexType>
<xsd:sequence>
<xsd:element ref="ot:othertest_element" />
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</xsd:schema>
</types>
</definitions>
othertest.wsdl
<definitions xmlns="http://schemas.xmlsoap.org/wsdl/"
xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
xmlns:http="http://schemas.xmlsoap.org/wsdl/http/"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:tns="http://www.example.com/othertest/"
targetNamespace="http://www.example.com/othertest/" >
<types>
<xsd:schema targetNamespace="http://www.example.com/othertest/">
<xsd:element name="othertest_element">
<xsd:simpleType>
<xsd:restriction base="xsd:int"/>
</xsd:simpleType>
</xsd:element>
</xsd:schema>
</types>
</definitions>
【问题讨论】:
-
import 元素中的“location”属性不应该是“schemaLocation”吗?
-
我不这么认为,因为我得到了导入元素中不允许 schemaLocation 并且属性位置必须在导入元素中的错误
-
啊,好吧——我的错。在 WSDL 中称为“位置”,在 XSD 中称为“schemaLocation”(参考:stackoverflow.com/questions/19284484/…)。你能用
代替 吗?我的一个 WSDL 中有这个: - 也许这会有所帮助? -
我只能在 xsd 命名空间 (
) 中使用包含,但是,这并不能解决问题,因为我保持相同的错误。我发现我可以在 元素中引用该元素,但不能在 元素中引用。因为我想用othertest.wsdl的多个不同元素来定义新元素,所以引用 元素内的元素不是解决办法。 -
是否有其他人知道我可以如何解决这个问题,而无需再次在 test.wsdl 中重新定义 othertest.wsdl 的元素?