【问题标题】:Axis WSDL with complex types faills to validate具有复杂类型的 Axis WSDL 无法验证
【发布时间】:2011-04-22 17:00:30
【问题描述】:

我正在经历一些 wsdl 模式命名空间的地狱。

我有一个来自 Axis Web 服务的 WSDL,我很想用 WCF 生成一个存根服务以进行测试。

问题是,SVCUTIL 工具可以很好地生成代码,但是在托管时,没有公开任何方法。

我检查了 WSDL 并且有一行验证失败。我正在尝试检查这是否是罪魁祸首,但命名空间是如此混乱,以至于我无法对其做出正面或反面。

所以,WSDL 大致是这样的。我省略了 WSDL 绑定、服务和端口,因为我只想专注于理解命名空间问题。

    <?xml version="1.0" encoding="UTF-8"?>
<wsdl:definitions xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"  xmlns:axis2="http://p1-services.customer.com/" 
                  xmlns:mime="http://schemas.xmlsoap.org/wsdl/mime/"  xmlns:ns0="http://returnobject.foo.bar.com/xsd" 
                  xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/"  xmlns:http="http://schemas.xmlsoap.org/wsdl/http/" 
                  xmlns:ns1="http://ws.receiver.foo.bar.com"  xmlns:wsaw="http://www.w3.org/2006/05/addressing/wsdl" 
                  xmlns:xs="http://www.w3.org/2001/XMLSchema"  xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" 
                  targetNamespace="http://p1-services.customer.com/">
    <wsdl:documentation>WSP1IA01Service</wsdl:documentation>
    <wsdl:types>
        <xs:schema xmlns:ax22="http://returnobject.foo.bar.com/xsd" 
                   attributeFormDefault="qualified"
                   elementFormDefault="qualified" targetNamespace="http://returnobject.foo.bar.com/xsd">
            <xs:complexType name="ReturnEnvelope">
                <xs:sequence>
                    <!-- Simplified -->
                    <xs:element minOccurs="0" name="errorCode" nillable="true" type="xs:string"/>
                </xs:sequence>
            </xs:complexType>
        </xs:schema>
        <xs:schema xmlns:ns="http://ws.receiver.foo.bar.com" attributeFormDefault="qualified" elementFormDefault="qualified" 
                   targetNamespace="http://ws.receiver.foo.bar.com">
            <xs:element name="setMessage">
                <xs:complexType>
                    <xs:sequence>
                        <xs:element minOccurs="0" name="xmlMessage" nillable="true" type="xs:string"/>
                    </xs:sequence>
                </xs:complexType>
            </xs:element>
            <xs:element name="setMessageResponse">
                <xs:complexType>
                    <xs:sequence>
                        <xs:element minOccurs="0" name="return" nillable="true"  type="ns0:ReturnEnvelope"/>
                    </xs:sequence>
                </xs:complexType>
            </xs:element>
        </xs:schema>
    </wsdl:types>
</wsdl:definitions>

验证失败的位是 SetMessageResponse 元素中对 ns0:ReturnEnvelope 的引用。它说找不到类型。

我不明白为什么,因为上面声明的类型是 targetNamespace 指向 NS0 前缀。

有什么想法吗?那些类型声明应该这么复杂吗?

另外,这个构造的目的是什么:

<xs:schema xmlns:ax22="http://returnobject.foo.bar.com/xsd"

我读过它声明了前缀“ax22”以便在子元素中进一步使用。但它没有被使用,并且与 NS0 命名空间发生冲突。

感谢您的帮助

【问题讨论】:

    标签: xml wcf wsdl xsd axis


    【解决方案1】:

    我不熟悉您的工具集,但我可以看到一个可能导致问题的问题。首先,一些基线:

    wsdl:types 中定义了两种模式。第一个用于命名空间http://returnobject.foo.bar.com/xsd,其中包含ReturnEnvelope 类型。

    第二个架构用于命名空间http://ws.receiver.foo.bar.com,并定义了http://returnobject.foo.bar.com/xsd命名空间中类型为ReturnEnvelope的元素setMessageResponse

    ax22 未使用且不必要,但它的存在不会干扰 ns0 表示相同的命名空间。

    第二个架构定义可以“看到”ns0,因为第二个架构定义嵌套在定义前缀的wsdl:definitions 内。但是,第二个模式不能使用该命名空间的模式内容(第一个模式);他们是没有联系的兄弟姐妹。要允许使用另一个命名空间的类型,您需要将 xs:import 元素添加到第二个架构:

    <xs:import namespace="http://returnobject.foo.bar.com/xsd"/>
    

    根据工具的不同,您可能还必须使用 schemaLocation 告诉它该架构的位置,但希望它可以弄清楚,因为它们彼此相邻。

    【讨论】:

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