【问题标题】:Referencing xml schema element from other WSDL file从其他 WSDL 文件引用 xml 模式元素
【发布时间】: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 的元素?

标签: xml import wsdl ref


【解决方案1】:

我有一个部分解决方案。似乎当我在 xsd 文件而不是 WSDL 文件中定义元素/类型并在 &lt;types&gt;&lt;xsd:schema&gt; 元素中使用 &lt;xsd:import namespace="..." schemaLocation="..." /&gt; 导入此文件时,它不会抱怨命名空间。但是,一旦我再次导入一个 wsdl 文件(其中包含了 &lt;types&gt; 中的类型和元素),它就会再次开始抱怨命名空间。

但是,仍然存在一个问题,即为我提供的是 wsdl 文件而不是 xsd 文件。 有没有办法在另一个 wsdl 文件的 &lt;types&gt; 部分重用 wsdl 文件中定义的元素/类型?

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多