代码之家  ›  专栏  ›  技术社区  ›  chris166

如何处理WCF中不正确的SOAP错误?

  •  3
  • chris166  · 技术社区  · 15 年前

    我必须使用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>
    

    错误是 <faultcode> 不能有命名空间:

    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 总是?

    2 回复  |  直到 15 年前
        1
  •  11
  •   WayneC    15 年前

    是的,但不太雅致。请参阅本论坛帖子底部的消息检查器代码:

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

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

        2
  •  -1
  •   Howard Hoffman    15 年前

    我相信比起wcf system.servicemodel.channels.servicechannel.handlereply/system.servicemodel.channels.messagefualt.createfault,旧版system.web.services.soaphttpclientProtocol类更能容忍不符合标准的错误。

    FWW。