使用 WCF 导入 WSDL 时出现问题

发布于 2024-11-05 13:58:23 字数 4686 浏览 3 评论 0原文

我正在尝试使用 WCF 为我公司的合作伙伴之一提供的 Web 服务导入 WSDL。 Web 服务是用 Java 编写的。我收到此错误:

警告:无法导入操作 getUnits 中名为 FooException 的错误。不支持 WSDL,故障消息部分必须引用元素。该错误消息未引用元素。如果您具有 WSDL 文档的编辑权限,则可以通过使用“element”属性引用架构元素来解决该问题。

好吧,实际上不是错误,但在生成的代码中 FooException 被忽略了。 FooException 包含我真正需要的错误代码。

我缩短了 WSDL,只保留了其中一种方法。我还重命名了一些东西(比如例外)。

<?xml version="1.0" encoding="UTF-8"?>
<wsdl:definitions targetNamespace="urn:testws.foo.se"
                  xmlns:apachesoap="http://xml.apache.org/xml-soap"
                  xmlns:impl="urn:testws.foo.se"
                  xmlns:intf="urn:testws.foo.se"
                  xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/"
                  xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
                  xmlns:wsdlsoap="http://schemas.xmlsoap.org/wsdl/soap/"
                  xmlns:xsd="http://www.w3.org/2001/XMLSchema">
  <!--WSDL created by Apache Axis version: 1.4
Built on Apr 22, 2006 (06:55:48 PDT)-->
  <wsdl:types>
    <schema targetNamespace="urn:testws.foo.se" xmlns="http://www.w3.org/2001/XMLSchema">
      <import namespace="http://schemas.xmlsoap.org/soap/encoding/" schemaLocation="http://schemas.xmlsoap.org/soap/encoding/"/>

      <complexType name="ArrayOf_soapenc_string">
        <complexContent>
          <restriction base="soapenc:Array">
            <attribute ref="soapenc:arrayType" wsdl:arrayType="soapenc:string[]"/>
          </restriction>
        </complexContent>
      </complexType>

      <complexType name="FooException">
        <sequence>
          <element name="errorCode" nillable="true" type="soapenc:string"/>
          <element name="errorDescription" nillable="true" type="soapenc:string"/>
          <element name="variables" nillable="true" type="impl:ArrayOf_soapenc_string"/>
        </sequence>
      </complexType>
      <element name="FooException" type="impl:FooException" nillable="true" />

      <complexType name="WsUnit">
        <sequence>
          <element name="id" nillable="true" type="soapenc:string"/>
          <element name="name" nillable="true" type="soapenc:string"/>
        </sequence>
      </complexType>

      <complexType name="ArrayOfWsUnit">
        <complexContent>
          <restriction base="soapenc:Array">
            <attribute ref="soapenc:arrayType" wsdl:arrayType="impl:WsUnit[]"/>
          </restriction>
        </complexContent>
      </complexType>
    </schema>
  </wsdl:types>

  <wsdl:message name="getUnitsRequest">
  </wsdl:message>
  <wsdl:message name="getUnitsResponse">
    <wsdl:part name="getUnitsReturn" type="impl:ArrayOfWsUnit"/>
  </wsdl:message>
  <wsdl:message name="FooException">
    <wsdl:part name="fault" type="impl:FooException"/>
  </wsdl:message>

  <wsdl:portType name="MyTest">
    <wsdl:operation name="getUnits">
      <wsdl:input message="impl:getUnitsRequest" name="getUnitsRequest"/>
      <wsdl:output message="impl:getUnitsResponse" name="getUnitsResponse"/>
      <wsdl:fault message="impl:FooException" name="FooException"/>
    </wsdl:operation>
  </wsdl:portType>

  <wsdl:binding name="MyTestSoapBinding" type="impl:MyTest">
    <wsdlsoap:binding style="rpc" transport="http://schemas.xmlsoap.org/soap/http"/>
    <wsdl:operation name="getUnits">
      <wsdlsoap:operation soapAction=""/>
      <wsdl:input name="getUnitsRequest">
        <wsdlsoap:body encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" namespace="urn:testws.foo.se" use="encoded"/>
      </wsdl:input>
      <wsdl:output name="getUnitsResponse">
        <wsdlsoap:body encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" namespace="urn:testws.foo.se" use="encoded"/>
      </wsdl:output>
      <wsdl:fault name="FooException">
        <wsdlsoap:fault encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" name="FooException" namespace="urn:testws.foo.se" use="encoded"/>
      </wsdl:fault>
    </wsdl:operation>
  </wsdl:binding>
  <wsdl:service name="MyTestService">
    <wsdl:port binding="impl:MyTestSoapBinding" name="MyTest">
      <wsdlsoap:address location="http://localhost:8080/axis/services/MyTest"/>
    </wsdl:port>
  </wsdl:service>
</wsdl:definitions>

我尝试将 FooException 的消息部分中的“type”更改为“element”,但这会导致错误。我还需要做什么?

I'm trying with WCF to import WSDL for a web service provided by one of my company's partners. The web service is written in Java. I get this error:

Warning: Fault named FooException in operation getUnits cannot be imported. Unsupported WSDL, the fault message part must reference an element. This fault message does not reference an element. If you have edit access to the WSDL document, you can fix the problem by referencing a schema element using the 'element' attribute.

Well, not actually an error, but in the generated code FooException is ignored. FooException contains an error code which I really need.

I've shortened the WSDL and only kept one of the methods. I've also renamed some things (like the exception).

<?xml version="1.0" encoding="UTF-8"?>
<wsdl:definitions targetNamespace="urn:testws.foo.se"
                  xmlns:apachesoap="http://xml.apache.org/xml-soap"
                  xmlns:impl="urn:testws.foo.se"
                  xmlns:intf="urn:testws.foo.se"
                  xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/"
                  xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
                  xmlns:wsdlsoap="http://schemas.xmlsoap.org/wsdl/soap/"
                  xmlns:xsd="http://www.w3.org/2001/XMLSchema">
  <!--WSDL created by Apache Axis version: 1.4
Built on Apr 22, 2006 (06:55:48 PDT)-->
  <wsdl:types>
    <schema targetNamespace="urn:testws.foo.se" xmlns="http://www.w3.org/2001/XMLSchema">
      <import namespace="http://schemas.xmlsoap.org/soap/encoding/" schemaLocation="http://schemas.xmlsoap.org/soap/encoding/"/>

      <complexType name="ArrayOf_soapenc_string">
        <complexContent>
          <restriction base="soapenc:Array">
            <attribute ref="soapenc:arrayType" wsdl:arrayType="soapenc:string[]"/>
          </restriction>
        </complexContent>
      </complexType>

      <complexType name="FooException">
        <sequence>
          <element name="errorCode" nillable="true" type="soapenc:string"/>
          <element name="errorDescription" nillable="true" type="soapenc:string"/>
          <element name="variables" nillable="true" type="impl:ArrayOf_soapenc_string"/>
        </sequence>
      </complexType>
      <element name="FooException" type="impl:FooException" nillable="true" />

      <complexType name="WsUnit">
        <sequence>
          <element name="id" nillable="true" type="soapenc:string"/>
          <element name="name" nillable="true" type="soapenc:string"/>
        </sequence>
      </complexType>

      <complexType name="ArrayOfWsUnit">
        <complexContent>
          <restriction base="soapenc:Array">
            <attribute ref="soapenc:arrayType" wsdl:arrayType="impl:WsUnit[]"/>
          </restriction>
        </complexContent>
      </complexType>
    </schema>
  </wsdl:types>

  <wsdl:message name="getUnitsRequest">
  </wsdl:message>
  <wsdl:message name="getUnitsResponse">
    <wsdl:part name="getUnitsReturn" type="impl:ArrayOfWsUnit"/>
  </wsdl:message>
  <wsdl:message name="FooException">
    <wsdl:part name="fault" type="impl:FooException"/>
  </wsdl:message>

  <wsdl:portType name="MyTest">
    <wsdl:operation name="getUnits">
      <wsdl:input message="impl:getUnitsRequest" name="getUnitsRequest"/>
      <wsdl:output message="impl:getUnitsResponse" name="getUnitsResponse"/>
      <wsdl:fault message="impl:FooException" name="FooException"/>
    </wsdl:operation>
  </wsdl:portType>

  <wsdl:binding name="MyTestSoapBinding" type="impl:MyTest">
    <wsdlsoap:binding style="rpc" transport="http://schemas.xmlsoap.org/soap/http"/>
    <wsdl:operation name="getUnits">
      <wsdlsoap:operation soapAction=""/>
      <wsdl:input name="getUnitsRequest">
        <wsdlsoap:body encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" namespace="urn:testws.foo.se" use="encoded"/>
      </wsdl:input>
      <wsdl:output name="getUnitsResponse">
        <wsdlsoap:body encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" namespace="urn:testws.foo.se" use="encoded"/>
      </wsdl:output>
      <wsdl:fault name="FooException">
        <wsdlsoap:fault encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" name="FooException" namespace="urn:testws.foo.se" use="encoded"/>
      </wsdl:fault>
    </wsdl:operation>
  </wsdl:binding>
  <wsdl:service name="MyTestService">
    <wsdl:port binding="impl:MyTestSoapBinding" name="MyTest">
      <wsdlsoap:address location="http://localhost:8080/axis/services/MyTest"/>
    </wsdl:port>
  </wsdl:service>
</wsdl:definitions>

I've tried to just change "type" to "element" in the message part for FooException, but it results in errors. What more do I need to do?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文