尝试使用来自第三方WSDL的故障元素在VS2013中创建服务引用时出错

时间:2014-07-31 18:22:00

标签: c# wcf wsdl

我正在使用提供的第三方WSDL为Web服务在VS 2013中创建一个WCF客户端 - 很可能是在Java上运行。

在原始WSDL上运行svcutil会给出类似于此的错误:

Error: Cannot import wsdl:binding
Detail: There was an error importing a wsdl:portType that the wsdl:binding is dependent on.
XPath to wsdl:portType: 
//wsdl:definitions[@targetNamespace='<ns>']/wsdl:portType[@name='xxxPort']       
XPath to Error Source: 
//wsdl:definitions[@targetNamespace='<ns>']/wsdl:binding[@name='xxxPortSoap11']

Error: Cannot import wsdl:port
Detail: There was an error importing a wsdl:binding that the wsdl:port is dependent on.
XPath to wsdl:binding: 
//wsdl:definitions[@targetNamespace='<ns>']/wsdl:binding[@name='xxxPortSoap11']
XPath to Error Source: 
//wsdl:definitions[@targetNamespace='<ns>']/wsdl:service[@name='xxxPortService']/wsdl:port[@name='xxxPortSoap11']

Generating files...
Warning: No code was generated. ...

为了使服务引用工作(或svcutil正常运行),我必须注释掉端口和绑定中的错误定义。我可以忍受(因为我已经使MessageInspector从各种细节元素中提取错误),但希望让它正常工作。

简化WSDL只显示给我带来问题的元素:

<?xml version="1.0" encoding="utf-8"?>
<wsdl:definitions 
xmlns:tns="http://www.example.com/data/common/" 
xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" 
xmlns:sch0="http://www.example.com/data/common/" 
targetNamespace="http://www.example.com/data/common/" 
xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/">
  <wsdl:types>

    <xsd:schema xmlns="http://www.w3.org/2001/XMLSchema" 
        xmlns:tns1="http://www.example.com/data/common/" 
        attributeFormDefault="unqualified" elementFormDefault="qualified" 
        targetNamespace="www.example.com/data/common/" 
        xmlns:xsd="http://www.w3.org/2001/XMLSchema">

    <xsd:complexType xmlns="http://www.w3.org/2001/XMLSchema" name="BusinessErrorType">
        <xsd:sequence xmlns="http://www.w3.org/2001/XMLSchema">
          <xsd:element xmlns="http://www.w3.org/2001/XMLSchema" 
             name="Error" maxOccurs="unbounded" type="string" />
        </xsd:sequence>
      </xsd:complexType>

      <xsd:element xmlns="http://www.w3.org/2001/XMLSchema" 
        name="BusinessErrorFault" type="tns1:BusinessErrorType" />

    </xsd:schema>

  </wsdl:types>

  <wsdl:message name="BusinessErrorFault">
    <wsdl:part name="BusinessErrorFault" element="sch0:BusinessErrorFault" />
  </wsdl:message>

  <wsdl:portType name="ViewMessagesPort">

    <wsdl:operation name="BusinessError">
      <wsdl:fault name="BusinessErrorFault" message="sch0:BusinessErrorFault" />
    </wsdl:operation>

  </wsdl:portType>

  <wsdl:binding name="ViewMessagesPortSoap11" type="sch0:ViewMessagesPort">

    <soap:binding transport="http://schemas.xmlsoap.org/soap/http" />

    <wsdl:operation name="BusinessError">
      <soap:operation soapAction="" />
      <wsdl:fault name="BusinessErrorFault">
        <soap:fault use="literal" name="BusinessErrorFault" />
      </wsdl:fault>
    </wsdl:operation>

  </wsdl:binding>

  <wsdl:service name="ViewMessagesPortService">
    <wsdl:port name="ViewMessagesPortSoap11" binding="sch0:ViewMessagesPortSoap11">
      <soap:address location="https://www.example.com/ws/" />
    </wsdl:port>
  </wsdl:service>

</wsdl:definitions>

我在网上看了很多SO问题和其他地方,包括Scott Hanselman's breaking the rules没有任何欢乐。

希望这是显而易见的事情......当我回到英国的路上时,我感激地等待着整个池塘的任何答案。

更新

通过https://www.wsdl-analyzer.com/传递上述WSDL会导致绑定错误:

Style: Unknown [Warn!]
Could not detect the 'use' for the operations of binding ViewMessagesPortSoap11

我仍然不是更聪明的人。

1 个答案:

答案 0 :(得分:3)

您在上面发布的WSDL存​​在一个问题,即没有架构的targetNamespace为&#34; http://www.example.com/data/common/&#34;这是sch0:BusinessErrorFault元素所期望的。我假设这可能是因为您没有提供完整的WSDL,所以我将架构的targetNamespace更改为它。如果这个操作出现下一个错误:

<wsdl:operation name="BusinessError">
      <wsdl:fault name="BusinessErrorFault" message="sch0:BusinessErrorFault" />
</wsdl:operation>

没有输入或输出,只有错误,这是自那以后没有。

我想这也可能是因为你简化了WSDL所以如果你得到更多的错误,请发布完整的WSDL。

相关问题