如何强制 WCF 线程中未处理的异常导致进程崩溃?
场景如下:
我有一个 WCF 服务,每个操作都定义了一堆FaultContract。 我想这样安排,如果在与有效的FaultContract不匹配的WCF服务线程中抛出未处理的异常,它会关闭整个进程而不仅仅是线程。 (原因是我想要一个包含异常信息的故障转储,因为它与合同不匹配。)
有什么方法可以干净地做到这一点吗? 我遇到的主要问题是 WCF 想要将我的所有异常转换为客户端故障,以保持服务运行; 我实际上想把整个过程拿下来,这本质上意味着规避 WCF 的正常行为。
So here's the scenario:
I have a WCF service that has a bunch of FaultContracts defined per operation. I would like to arrange it such that if an unhandled exception is thrown in a WCF service thread that does not match a valid FaultContract, it takes down the entire process rather than just the thread. (The reason being that I would like a crash dump that contains the information on the exception, since it didn't match the contract.)
Is there any way to do this cleanly? The main problem I have is that WCF wants to translate all my exceptions into a client-side fault in order to keep the service running; I actually want to take the entire process down, which essentially means circumventing WCF's normal behavior.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
Environment.FailFast() 将创建故障转储; 它不会运行任何挂起的 try-finally 块,也不会运行任何终结器。
Environment.FailFast() will create a crash dump; it will not run any pending try-finally blocks nor will it run any finalizers.
您需要使用 IErrorHandler 来自定义 WCF错误处理行为。 在调用 (ServiceHost).Open() 之前“应用该行为”。
例如(在 Main() 中查找“serviceHost.Description.Behaviors.Add(new FailBehavior());”行):
You need to use IErrorHandler to customize WCF's error handling behavior. You "apply the behavior" before you call (ServiceHost).Open().
For example (look for the line that says "serviceHost.Description.Behaviors.Add(new FailBehavior());" in Main()):
这可能会成功,但用户将丢失他们当时正在处理的任何内容。
That might do it, but the user will lose anything they're working on at the time.