哪些情况会导致WCF代理出现故障?

发布于 2024-07-29 07:17:05 字数 732 浏览 11 评论 0原文

我想知道WCF代理(由vs2008或svcutil生成)在什么情况下会出现故障(故障状态)? 这样我就可以重新创建新实例并避免使用有故障的实例。

目前我正在处理 TimeoutException、FaultException、CommunicationObjectAbortedException

            try
            {
                client.Method1(args);
            }
            catch (TimeoutException)
            {
                client.Abort();
                ReCreate();
            }
            catch (FaultException)
            {
                client.Abort();
                ReCreate();
            }
            catch (CommunicationObjectAbortedException)
            {
                client.Abort();
                ReCreate();
            }

我想我可以避免所有这些类型并仅处理父 CommunicationException,这是否足够? 我需要评论

I want to know what are the cases in which WCF proxy (generated by vs2008 or svcutil) becomes faulted (fault state)? so I can recreate new instance and avoid use the faulted one.

currently I am handling TimeoutException,FaultException,CommunicationObjectAbortedException

            try
            {
                client.Method1(args);
            }
            catch (TimeoutException)
            {
                client.Abort();
                ReCreate();
            }
            catch (FaultException)
            {
                client.Abort();
                ReCreate();
            }
            catch (CommunicationObjectAbortedException)
            {
                client.Abort();
                ReCreate();
            }

I think I can avoid all these types and handle only the parent CommunicationException, is this sufficient? I need comments

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

岁月染过的梦 2024-08-05 07:17:05

服务器端未处理并转换为 FaultExceptionFaultException 的任何未捕获异常都可能导致您的通道出现故障。 在每次调用场景或单向场景中,您通常并不真正关心通道出现故障,但在基于会话的场景中,您肯定会关心!

最好的选择是真正尝试捕获服务器端的所有异常,然后抑制它们(将它们记录在服务器上并且不执行任何操作),或者以 FaultException 将它们返回给客户端方式。

为此,您的服务实现还应该实现 IErrorHandler 接口允许您执行此操作 - 捕获所有异常并记录+抑制它们,或将它们转换为 SOAP 错误。

马克

Any uncaught exception on the server side that isn't handled and converted into a FaultException or FaultException<T> will likely fault your channel. In a per-call scenario or a one-way scenario, you often don't really care about the channel being faulted, but in a session-based scenario, you definitely will!

Your best bet is to really try and catch all exceptions on the server side and either just suppress them (log them on the server and don't do anything), or return them to the client in a FaultException way.

In order to do that, your service implementation should also implement the IErrorHandler interface which allows you to do just that - catch all exceptions and either logging+suppressing them, or converting them to SOAP faults.

Marc

苍暮颜 2024-08-05 07:17:05

WCF 代理对象可能会因为除故障异常之外的任何类型的异常而出现故障。 因此,基本上,您最好的选择就是检查代理状态,如果出现故障,请创建一个新代理。

另一件需要记住的事情是故障与 WCF 会话有关。 如果您不需要 WCF 会话,请确保将其关闭,这样您就可以避免一系列可能出现的问题。

WCF proxy object can become faulted because of any sort of exception except a faultException. So basically you best bet is just to check the proxy state and of it is faulted create a new one.

Another thing to keep in mind is that faulted is related to WCF sessions. If you don't need WCF sessions make sure to turn them off and you have prevented a whole series of possible issues.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文