微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

xml – 导入命名空间的Eclipse WSDL验证错误

我收到了组织中服务团队的非内联WSDL文件,在将所有XSD添加Eclipse中的XML目录后,我发现他们的主要WSDL文件没有验证.它似乎没有找到< wsdl:message> < wsdl:import>中定义的元素.验证错误是这样的:

The fault element is referencing an undefined message ‘serviceFault’. Check that the message name and namespace are correct and that the message has been defined.

所有文件路径都是相同的文件夹.这是一个重新创建验证错误的小测试示例:

test.xsd

<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema 
    targetNamespace="http://www.example.org/test" xmlns="http://www.example.org/test"
    elementFormDefault="qualified" attributeFormDefault="unqualified"
    xmlns:xsd="http://www.w3.org/2001/XMLSchema"
    xmlns:ibmSchExtn="http://www.ibm.com/schema/extensions">

    <xsd:complexType name="ServiceFaultType">
        <xsd:sequence>
            <xsd:element name="code" type="xsd:string" />
            <xsd:element name="message" type="xsd:string" />
            <xsd:element minOccurs="0" name="detail" type="xsd:string" />
        </xsd:sequence>
    </xsd:complexType>

    <xsd:element ibmSchExtn:docRoot="true" name="serviceFault"
        type="ServiceFaultType" />
</xsd:schema>

common.wsdl

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<wsdl:deFinitions xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
    targetNamespace="http://www.example.org/test" xmlns="http://www.example.org/test"
    xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
    <wsdl:documentation>
        <wsdl:appinfo source="WMQI_APPINFO">
            <MRWSDLAppInfo xmlns="urn:xxx.xxx.xxxbank.com/common/service"
                imported="true" />
        </wsdl:appinfo>
    </wsdl:documentation>
    <wsdl:types>
        <xs:schema elementFormDefault="qualified">
            <xs:import namespace="http://www.example.org/test"
                schemaLocation="test.xsd" />
        </xs:schema>
    </wsdl:types>
    <wsdl:message name="serviceFault">
        <wsdl:part element="serviceFault" name="fault" />
    </wsdl:message>
</wsdl:deFinitions>

test.wsdl

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<wsdl:deFinitions xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
    targetNamespace="urn:testservice" xmlns="urn:testservice"
    xmlns:http="http://schemas.xmlsoap.org/wsdl/http/"
    xmlns:ns="http://www.example.org/test"
    xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
    xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/"
    xmlns:xsd="http://www.w3.org/2001/XMLSchema">


    <wsdl:import namespace="http://www.example.org/test" location="common.wsdl"></wsdl:import>
    <wsdl:types>
        <xsd:schema targetNamespace="urn:testservice">
            <xsd:element name="NewOperation">
                <xsd:complexType>
                    <xsd:sequence>
                        <xsd:element name="in" type="xsd:string" />
                    </xsd:sequence>
                </xsd:complexType>
            </xsd:element>
            <xsd:element name="NewOperationResponse">
                <xsd:complexType>
                    <xsd:sequence>
                        <xsd:element name="out" type="xsd:string" />
                    </xsd:sequence>
                </xsd:complexType>
            </xsd:element>
        </xsd:schema>
    </wsdl:types>
    <wsdl:message name="NewOperationRequest">
        <wsdl:part element="NewOperation" name="parameters" />
    </wsdl:message>
    <wsdl:message name="NewOperationResponse">
        <wsdl:part element="NewOperationResponse" name="parameters" />
    </wsdl:message>
    <wsdl:portType name="test">
        <wsdl:operation name="NewOperation">
            <wsdl:input message="NewOperationRequest" />
            <wsdl:output message="NewOperationResponse" />
            <wsdl:fault message="ns:serviceFault" name="fault" />
        </wsdl:operation>
    </wsdl:portType>
    <wsdl:binding name="testSOAP" type="test">
        <soap:binding style="document"
            transport="http://schemas.xmlsoap.org/soap/http" />
        <wsdl:operation name="NewOperation">
            <soap:operation soapAction="http://www.example.org/test/NewOperation" />
            <wsdl:input>
                <soap:body use="literal" />
            </wsdl:input>
            <wsdl:output>
                <soap:body use="literal" />
            </wsdl:output>
        </wsdl:operation>
    </wsdl:binding>
    <wsdl:service name="test">
        <wsdl:port binding="testSOAP" name="testSOAP">
            <soap:address location="http://www.example.org/" />
        </wsdl:port>
    </wsdl:service>
</wsdl:deFinitions>

如果将test.xsd添加到Eclipse中的XML目录,则会演示验证错误.他们坚持认为他们的WSDL或模式没有任何问题,JAX-WS似乎可以使用wsimport生成代理.此外,它似乎在与端点通信时编组和解组请求和响应.

这可能是Eclipse的WSDL验证中的错误吗?

编辑:只是一个想法,即使我仍然没有解决问题.我认为可能会发生的是Eclipse正在验证test.xsd的命名空间,但是该命名空间中的common.wsdl声明了自己的元素.当Eclipse在ns命名空间中查找这个常见的ns:serviceFault时,它显然不会在test.xsd中找到它.这让我觉得Eclipse WSDL验证在这里应该更加智能,并确定WSDL导入并包含其中的所有内容以及在其XML目录中声明的模式.如果我在这里,我仍然不知道如何解决它.是否有一个Eclipse的功能可以正确地验证这种类型的WSDL情况?

解决方法

我在我身边创建了文件,并使用Eclipse Luna 4.4.0和Web Developer Tools 3.2.5进行了测试.我将两个.wsdl文件放在同一个通用项目中,然后通过向导在XML目录中导入.xsd.

当我验证每个文件时,Eclipse没有发现任何错误/警告.我确实只是在从项目中删除了common.wsdl文件时才会收到错误消息,但这是因为它是在test.wsdl中导入的.我还尝试在SoapUI 5.0.0中使用test.wsdl(来自Eclipse目录)创建一个新的SoapUI项目,它也没有抱怨.

由于我无法重现错误,我认为它可能是您正在使用的特定Eclipse版本的错误或Web Developer Tools的错误.或者它可能是一些当地的废话,只是一眼就看不到.再次确保Eclipse实际上将所有文件物理地放在文件系统的同一目录中.

如果您决定更改版本,请参阅我的Eclipse配置的screenshot以供您比较.

我很高兴能够进一步帮助你,但至少我告诉你这个问题是本地的.祝好运!

评论1后更新1

最初,我通过Import-> XML-> XML Catalog导入了test.xsd.现在我将.xsd移动到另一个文件系统位置并将其从项目中删除(因为否则它始终有效).然后,我按照您的建议(Window-> Preferences-> XML-> XML catalog->用户指定的条目 – > Catalog Entry-> From filesystem:key type =尝试命名空间名称和Schema位置)和key = http://www.example.org/test).执行此操作后,我收到警告错误读取.xsd文件(指向项目的本地目录而不是新位置)和多个错误,其中一个是您的错误.

如果我删除common.wsdl中的schemaLocation =“test.xsd”属性并将keytype设置为Namespace,那么common.wsdl可以正常工作并且没有错误,但test.wsdl说:

fault元素引用了未定义的消息’serviceFault’.检查消息名称名称空间是否正确以及消息是否已定义.

我看到common.wsdl有两个具有相同命名空间名称的命名空间:xs和xsd(“http://www.w3.org/2001/XMLSchema”).这会导致错误吗?

更新2

我进一步调查了,我找到了this wiki page,解释了使用XML目录和模式.根据它,行为有点预期:

Note : If your XML document specificed relative schema locations (e.g. ‘foo.xsd’ as show below) then an XML Schema can NOT be registered using “foo.xsd” as the Schema Location key. Todo: reference section below that describes why this is the case and how XML Catalog v1.1 provides a way to partially solve this. <xyz:foo xmln:xyz="http://www.example.org/foo/" xsi:schemaLocation="foo.xsd" ...

所以他们似乎知道这些相对路径存在问题.

然后我尝试在目录密钥和schemaLocation中使用完整的URI,它没有错误

我将继续研究这个问题(我在Eclipse论坛上找到了this thread,其中讨论了类似的主题)如果弹出某些内容我会发布更新.

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。