如何从 WCF 客户端访问 SOAP 1.1 故障详细信息(无故障合同) [英] How to access SOAP 1.1 fault detail from WCF client (no fault contract)

查看:23
本文介绍了如何从 WCF 客户端访问 SOAP 1.1 故障详细信息(无故障合同)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在访问 SOAP 1.1 Web 服务,但它返回了一个错误.据我所知,Web 服务没有在 WSDL 中定义任何错误契约.我的 WCF 客户端将故障映射到 FaultException(而不是 FaultException).这都是有道理的.问题是该服务正在故障的 detail 元素中返回一些有用的诊断信息,我想访问这些信息以便我可以将其转储到跟踪日志中.似乎 FaultException 不提供对 detail 元素的任何访问,大概是因为没有错误合同,它不知道那里有什么.

I'm accessing a SOAP 1.1 web service, and it's returning a fault. The web service does not define any fault contract in the WSDL as far as I can see. My WCF client maps the fault to a FaultException (rather than a FaultException<T>). This all makes sense. The problem is that the service is returning some useful diagnostic information in the detail element of the fault, which I'd like to access so that I can dump it to a trace log. It seems that FaultException does not provide any access to the detail element, presumably because without a fault contract it doesn't know what is in there.

但我不需要反序列化细节 XML - 只需将原始 XML 作为字符串就可以用于诊断目的.

But I don't need to deserialize the detail XML - just the raw XML as a string will do fine for diagnostic purposes.

在这种情况下,有没有办法从 WCF 客户端访问详细的 XML?

Is there any way to get access to the detail XML from a WCF client, in this scenario?

推荐答案

详见此处:http://www.theruntime.com/blogs/jacob/archive/2008/01/28/getting-at-the-details.aspx

您可以使用此解决方法获取详细信息:

you can use this workaround to obtain the details:

} catch (FaultException soapEx)
{    
    MessageFault mf = soapEx.CreateMessageFault();    
    if (mf.HasDetail)
    {    
        XmlDictionaryReader reader = mf.GetReaderAtDetailContents();    
        ...    
    }    
}

这篇关于如何从 WCF 客户端访问 SOAP 1.1 故障详细信息(无故障合同)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆