【问题标题】:How to handle incorrect SOAP fault in WCF?如何处理 WCF 中不正确的 SOAP 错误?
【发布时间】:2010-02-18 09:52:57
【问题描述】:

我必须使用 SOAP 消费到第三方 Web 服务。很容易让它与 WCF 一起工作,但现在我遇到了 SOAP 错误的问题。该服务向我发送了一个不正确的 SOAP 错误:

<?xml version="1.0" encoding="utf-8" ?>
<SOAP-ENV:Envelope 
    SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" 
    xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
    <SOAP-ENV:Body>
        <SOAP-ENV:Fault>
            <SOAP-ENV:faultcode>14</SOAP-ENV:faultcode>
            <SOAP-ENV:faultstring>Unknown Function</SOAP-ENV:faultstring>
        </SOAP-ENV:Fault>
    </SOAP-ENV:Body>
</SOAP-ENV:Envelope>

错误是&lt;faultcode&gt;不能有命名空间:

System.ServiceModel.CommunicationException : Server returned an invalid 
SOAP Fault. Please see InnerException for more details.
    ----> System.Xml.XmlException : Start element 'faultcode' from namespace 
    '' expected. Found element 'SOAP-ENV:faultcode' from namespace 
    'http://schemas.xmlsoap.org/soap/envelope/'.

我无法更改原始 Web 服务 - 但 WCF 中是否有任何东西可以用来以某种方式处理这些错误消息,而不会一直收到 CommunicationException

【问题讨论】:

    标签: wcf soap wcf-client


    【解决方案1】:

    是的,但它并不完全优雅。请参阅此论坛帖子底部的消息检查器代码:

    http://social.msdn.microsoft.com/Forums/en-US/wcf/thread/435850aa-bf74-4158-a29a-256135207948

    基本上,您可以获取传入的消息并对其进行更改,以便 WCF 处理它。

    【讨论】:

    • 谢谢,这正是我所需要的!而且它足够优雅:)
    【解决方案2】:

    我相信老式 System.Web.Services.SoapHttpClientProtocol 类比 WCF System.ServiceModel.Channels.ServiceChannel.HandleReply / System.ServiceModel 更能容忍不符合标准的错误。 Channels.MessageFualt.CreateFault。

    FWIW。

    【讨论】:

      猜你喜欢
      • 2023-03-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-12-04
      • 1970-01-01
      相关资源
      最近更新 更多