如何处理WCF中不正确的SOAP故障?

6

我需要使用SOAP调用第三方网络服务。使用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个回答

12

谢谢,这正是我所需要的!并且足够优雅 :) - chris166

-1

我相信老派的System.Web.Services.SoapHttpClientProtocol类比WCF System.ServiceModel.Channels.ServiceChannel.HandleReply / System.ServiceModel.Channels.MessageFualt.CreateFault更容忍不达标准的故障。

顺便说一下。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接