如何防止 WCF 服务进入故障状态? [英] How do I prevent a WCF service from enter a faulted state?

查看:34
本文介绍了如何防止 WCF 服务进入故障状态?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个不应进入故障状态的 WCF 服务.如果出现异常,则应将其记录下来,并且服务应继续不间断.该服务具有单向操作契约,并且正在从 MSMQ 读取消息.

I have a WCF Service that should not enter the faulted state. If there's an exception, it should be logged and the service should continue uninterrupted. The service has a one-way operation contract and is reading messages from an MSMQ.

我的问题有两个:

  1. 服务似乎正在吞咽异常/故障,所以我无法调试它.我如何获得服务公开异常,以便我可以记录或处理吗?
  2. 服务是进入故障状态后这个异常被吞了.怎么办我阻止服务进入进入故障状态?

推荐答案

在 WCF 跟踪 (配置跟踪),最好使用 服务跟踪查看器.

Most, if not all exceptions can be seen in the WCF Trace (Configuring Tracing) and the trace is best viewed with the Service Trace Viewer.

显然,这不是您应该在生产环境中整天运行的东西,但无论如何它有助于故障排除.

Obviously, this is not something you should have running all day in a production environment, but it helps in troubleshooting anyway.

除此之外,请注意,根据您使用的 SessionMode,oneways 可能不会作为真正的即发即弃"运行.如果您为 SessionMode.Allowed 或什至 SessionMode.Required 配置了您的服务,则单向操作将运行,就好像它根本不是单向一样(这可以在通过 netTcpBinding 使用单向时观察到).然而,坦率地说,我不知道这是否会改变您可以获得的异常类型,或者何时获得它们.但是,无论如何,如果根本无法发送请求,您应该得到一个异常.AFAIK,当它在服务器端成功排队时,单向结束".因此,在此之前(想到序列化/反序列化)还有一些(与 WCF 框架相关的)异常.

Apart from that, note that oneways may not run as a true "fire and forget" depending on the SessionMode you use. If you have your service configured for SessionMode.Allowed or even SessionMode.Required, the oneway operation will run as if it was not oneway at all (this can be observed when using oneways over the netTcpBinding). To be frank, however, I don't know if that changes the type of exceptions you can get, or when you get them. However, in any case, you should get an exception if the request could not be send at all. AFAIK, the oneway "ends" when it is successfully enqued on the server side. So there is some place for (WCF framework related) exceptions until then (serialization/deserialization comes to mind).

然后,使用上面提到的跟踪/跟踪查看器可以最好地看到此类与框架相关的异常(即使 IErrorHandler 由于在请求/响应流中被调用而无法全部获取它们).

Then, such framework related exceptions are best seen (even an IErrorHandler doesn't get them all due to the fact when it is called in the request/response-flow) using the above mentioned trace / traceviewer.

这篇关于如何防止 WCF 服务进入故障状态?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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