- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
我成功地使用了第三方 soap 服务。我添加了对自动生成类的 soap Web 服务的服务引用。
当发生错误时,它会返回这样的 soap 响应:
<SOAP-ENV:Envelope xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
<SOAP-ENV:Body>
<SOAP-ENV:Fault>
<faultcode>SOAP-ENV:Client</faultcode>
<faultstring xsi:type="xsd:string">Error while reading parameters of method 'Demo'</faultstring>
<detail xsi:type="xsd:string">Invalid login or password. Connection denied.</detail>
</SOAP-ENV:Fault>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
我可以捕获错误但无法提取细节。我尝试了以下代码:
catch (FaultException ex)
{
MessageFault msgFault = ex.CreateMessageFault();
var elm = msgFault.GetDetail<string>();
//throw Detail
}
但是由于详细信息节点不是对象,它会出现以下错误:
Expecting element 'string' from namespace 'http://schemas.datacontract.org/2004/07/MyDemoNamespace'.. Encountered 'Text' with name '', namespace ''.
这是第三方 API,所以我无法更改响应。
最佳答案
消息错误的详细信息节点应包含 XML。 GetDetail 会将此 XML 反序列化为给定对象。
由于内容不是 XML,因此可以使用此方法。
但是您可以访问 XML 并读取 innerXml 值:
MessageFault msgFault = ex.CreateMessageFault();
var msg = msgFault.GetReaderAtDetailContents().Value;
这种方法奏效了。
关于c# - 从 WCF FaultException 响应中提取详细信息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16523399/
我已经阅读了关于此的所有内容,但也许我遗漏了一些东西(好吧,我肯定遗漏了一些东西,否则它已经可以工作了) 我在我的服务器业务层中抛出了一些异常错误: public class RfcException
好的,我知道我在这里遗漏了一些东西。我有以下操作合约: public double DivideByZero(int x, int y) { if (y =
什么更有效?抛出异常或抛出错误……我认为有两种情况: 发生异常并被捕获,是否抛出现有的 Exception或新建 FaultException然后扔那个? 您自己的逻辑(例如用户名不能为空)需要将错误
我有一个 WCF 服务,如果出现问题,它会抛出一个通用的 FaultException。 我不知道为什么,有时客户端会捕获非泛型 FaultException 而不是泛型异常。 有谁知道,问题是什么?
我们目前有一种在测试页面中调用网络服务的机制。但是,我正在尝试查看 WCF 服务的更好做法并使用 FaultException。 所以有我们服务抛出FaultException的情况,我想将该故障序列
我发布了一个question关于使用消息与故障异常在服务之间传达业务规则。 我的印象是通过网络抛出这个异常会带来开销,但考虑到它只是一条被序列化和反序列化的消息,它们实际上是一样的。 但这让我开始考虑
我有一个关于如何将自定义异常作为FaultException 发送的问题。当我使用像 ArgumentException 这样的系统异常时它可以工作,但是如果我将其更改为自定义异常“TestExcep
我有一个非常简单的 3 层项目。有一个与数据存储交互的 DAL(数据访问层)WCF 服务; BLL(业务逻辑层)WCF 服务作为 DAL 服务和客户端 UI 以及 Windows 窗体客户端层之间的中
我正在尝试在 WCF 服务中实现异常处理。我希望将此异常抛出给客户端,以便记录和处理它。 我不知道我写的代码是对还是错。这只会让我“faultexception 未被用户代码处理”我应该如何解决才能处
对于以下异常,没有在异常窗口中指定原因(->查看详细信息): System.ServiceModel.FaultException The creator of this fault did not
在我的 WCF 服务上,我有几个自定义故障类型。一个名为 BaseFault 的抽象类型及其两个实现,分别称为 TypeOneFault 和 TypeTwoFault 我是这样在服务端抛出异常的 pu
单层应用程序可以通过以下方式区分异常: Exception ex; if (ex is System.DirectoryServices.AccountManagement.PasswordExcep
我正在使用 C# 从 .NET 4.5 调用 SOAP Web 服务,但我不明白如何捕捉未类型化 FaultException 的详细信息. 如果 Web 服务遇到错误,我会收到如下消息:
我在调用服务 API 时捕获了 FaultException,例如 catch(FaultException e) { // How do I get the MyCustomEx objec
我有一些预定义的 WCF 服务 FaultContract属性。当FaultException抛出异常,它们会发送 StackTrace、Source 和其他可能未保存的信息。 是否可以只返回: 详细
我为每个帖子都提供了一个pingback列表。看起来像这样: def send_trackback #do stuff begin Pingback::Client.new.ping(
我正在了解 WCF 服务上下文中的 FaultException 和 CLR 异常,但有些内容尚不清楚。在“Learning WCF”一书中,它说当服务抛出一个正常的 CLR 异常时,它会被服务模型捕
在更新我的 WCF 客户端的服务引用时(只需在 Visual Studio 2008 中单击“更新服务引用”),出现以下错误:System.ServiceModel.FaultException: T
我正在尝试在带有 .net 4.5 的 VS 2012 中使用带有 Telerik OpenAccess 的 WCF Plain 服务。 我尝试了 telerik 开发人员手册并创建了服务和客户端。
我只是在检查 WCF FaultContract。根据它的定义,它用于向客户端发送异常详细信息。但是我们可以只使用 FaultException 来做到这一点。那么为什么我们需要 FaultContr
我是一名优秀的程序员,十分优秀!