如何在IDispatchMessageInspector中获取异常对象?

时间:2017-01-25 14:35:39

标签: c# wcf idispatchmessageinspector operationcontext

我的 WCF 应用程序使用#ct-skills{ background: grey; width: 100%; text-align: center; border: 3px solid green; display: flex; justify-content: center; align-items: center; flex-direction: column; } h3{ font-size: 24px; font-family: "Raleway"; color: rgb(255, 255, 255); font-weight: bold; text-transform: uppercase; border: 2px solid blue; } #skills-circles{ display: flex; border: 1px solid yellow; float: none; margin: 0 auto; flex-wrap: wrap; padding: 20px; } .ct-circle{ min-height: 150px; min-width: 150px; display: flex; flex-direction: column; align-items: stretch; justify-content: center; margin: 20px; } .circle{ min-height: 100%; min-width: 100%; box-sizing: border-box; border: 5px solid black; border-radius: 50%; font-size: 16px; font-family: "Raleway"; color: rgb(255, 255, 255); display: flex; align-items: center; justify-content: center; } span{ font-size: 16px; font-family: "Raleway"; color: rgb(255, 255, 255); } 进行某些高级监控 - 发生错误时发生错误

当我到达IDispatchMessageInspector方法时,我正在寻找一种方法来获取我的服务中发生的异常,因为我需要根据异常类型执行特定操作。

正在寻找修改\记录我的错误,因为我已经使用自定义IDispatchMessageInspector.BeforeSendReply执行此操作。

当我进入IErrorHandler时,我考虑过向OperationContext添加例外,当我回到IErrorHandler时只是阅读它,但我更喜欢内置的内容

当我使用IDispatchMessageInspector方法时,有什么办法可以获取异常吗?也许在OperationContext的某个地方?

1 个答案:

答案 0 :(得分:0)

IDispatchMessageInspector interface 允许您在调度之前查看到达端点的消息以及在将其发送回客户端之前的相应响应消息。

  

关于可能有用的 BeforeSendReply() 方法,需要注意几点:

  • 如果发送消息的操作是单向的 在操作中,此方法仍将由WCF运行时调用 操作具有的IDispatchMessageInspector实现 完成了它的执行。然而,"回复"论证代表 响应消息将为null,因此请务必检查该消息 在操纵消息之前。
  • 您可以在实施中检测消息的操作 通过检查IsFault被派遣去抛出异常/错误 回复消息的属性。对于单向来说,这甚至是正确的 operations (即使客户端永远不会看到它,服务器端 调度员仍然正确地通知消息检查员有关它的信息)