开发者

How to handle incorrect SOAP fault in WCF?

开发者 https://www.devze.com 2022-12-21 00:20 出处:网络
I have to consume to a third-party web service using SOAP. It was easy to get it to work with WCF, but now I have a problem with SOAP faults. The service sends me an incorrect SOAP fault:

I have to consume to a third-party web service using SOAP. It was easy to get it to work with WCF, but now I have a problem with SOAP faults. The service sends me an incorrect SOAP fault:

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

The error is that the <faultcode> must not have a namespace:

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/'.

I can't change the original web service - but is there anything in WCF I can use to still handle thes开发者_如何学Ce fault messages in some way without getting CommunicationException all the time?


Yes, but it's not exactly elegant. See the message inspector code at the bottom of this forum post:

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

Basically, you can take the incoming message and alter it so that it can be handled by WCF.


I believe the old-school System.Web.Services.SoapHttpClientProtocol class is more tolerant of not-up-to-snuff-or-standard Faults than the WCF System.ServiceModel.Channels.ServiceChannel.HandleReply / System.ServiceModel.Channels.MessageFualt.CreateFault.

FWIW.

0

精彩评论

暂无评论...
验证码 换一张
取 消