简体   繁体   English

如何在启用会话的 WCF 双工服务中处理故障 state

[英]How to deal with faulted state in a WCF duplex service with sessions enabled

I have a duplex WCF service with sessions enabled, and I'm trying avoid fault state exceptions on the client.我有一个启用了会话的双工 WCF 服务,并且我正在尝试避免客户端上出现错误 state 异常。

I found several discussions arround this topic, but all I have found suggest to recreate the client proxy or channel.我发现了围绕这个主题的几个讨论,但我发现的所有内容都建议重新创建客户端代理或通道。 Non is focus in duplex services with session enabled. Non 专注于启用 session 的双工服务。

My problem with that approach is that there is one session per client in the server, and each client has only one instance of the service proxy (singleton service proxy).我对这种方法的问题是服务器中的每个客户端都有一个 session,每个客户端只有一个服务代理实例(单例服务代理)。 Because it is duplex, in the client side several objects are listening to events on that service instance (messages sent from the server to the client).因为它是双工的,所以在客户端有几个对象正在监听该服务实例上的事件(从服务器发送到客户端的消息)。 If the service is in faulted state, it can not be used any more.如果该服务在故障state,则不能再使用。 If I discard that instance and create a new one, I'm finding it hard to hook up all the event handlers again to this new instance.如果我丢弃该实例并创建一个新实例,我会发现很难将所有事件处理程序再次连接到这个新实例。

Should I wrap the service and every time an object hooks up for an event, store the handler in a list (so that I can re hook it when service is recreated)?我是否应该包装服务,并且每次 object 连接事件时,将处理程序存储在列表中(以便在重新创建服务时重新连接它)? Seems to be lost of code, easy to leak memory...好像丢了代码,容易泄露memory...

Is there a way to just restart the client proxy / channel, without discarding all the proxy instance?有没有办法只重新启动客户端代理/通道,而不丢弃所有代理实例? (I'm using the VS generated proxy) (我正在使用 VS 生成的代理)

Any ideas?有任何想法吗?

Thanks, MAB谢谢,MAB

You cannot restart the proxy.您无法重新启动代理。 The only recovery from faulted state is aborting current instance and recreating the new one.从故障 state 中恢复的唯一方法是中止当前实例并重新创建新实例。 On the client side you must correctly unregister everything dependent on your proxy instance, create new instance and register everything again.在客户端,您必须正确取消注册依赖于您的代理实例的所有内容,创建新实例并再次注册所有内容。 This whole operation must happen once you get the exception about channel in faulted state (= when you try to call the service).一旦您在故障 state 中获得有关通道的异常(= 当您尝试调用服务时),就必须执行整个操作。 After recreation you must call the service again.娱乐后,您必须再次致电该服务。

On the service side the instance is either already dead (that caused the faulted state of the channel) or it will die after session timeout.在服务端,实例要么已经死亡(导致通道出现故障 state),要么在 session 超时后死亡。 You must also handle faulted exception when you try to callback on the faulted channel by removing the channel from your known clients and unregistering anything dependent on that channel.当您尝试通过从已知客户端删除通道并取消注册依赖于该通道的任何内容来尝试在故障通道上回调时,您还必须处理故障异常。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM