本文介绍了如何处理 WCF 中不正确的 SOAP 错误?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

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

I can't change the original web service - but is there anything in WCF I can use to still handle these 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

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

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

这篇关于如何处理 WCF 中不正确的 SOAP 错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

05-26 21:18
查看更多