WCF 代理对服务关闭做出反应时出现问题

发布于 2024-10-02 03:14:28 字数 738 浏览 0 评论 0原文

我有一个自定义(通用)代理类,用于连接到我的 WCF 服务。我想为此类提供的功能之一是能够从服务故障(即故障的通信通道)和关闭中“恢复”。为此,我获取了对服务通道的引用并订阅了 ICommunicationObject.Closed 和 ICommunicationObject.Faulted 事件。当这些事件发生时,我启动一个“恢复”过程,基本上每隔几秒钟尝试重新建立与服务的连接。假设是,如果服务由于某种原因变得不可用,它很快就会再次可用,并且客户端应用程序可以恢复原来的位置。

我有两项服务。服务 A 需要回调合约,而服务 B 不需要。服务 A 使用双工通道,服务 B 则不使用。两者都需要会话。服务A隐式创建会话;服务 B 定义了 IsInitiating 和 IsTerminate 操作。这是我看到的(有点令人困惑的)行为:

Service A

  • Graceful shutdown ->会引发Faulted 事件并可由代理处理,但不能处理Closed 事件。
  • “硬”关机->与上面相同。

服务 B

  • 正常关闭 - 不会引发任何事件。
  • “硬”关闭 - 不会引发任何事件。

请注意,这两个服务使用相同的代理类。唯一的区别在于它们的初始化方式。代理 A 使用双工通道工厂,因此必须创建一个实例上下文,将实现服务 A 的回调协定的实例传递到该实例上下文。代理 B 仅使用“常规”通道工厂。

有什么想法吗?

非常感谢, J。

I have a custom (generic) proxy class that I use to connect to my WCF services. One of the functionalities I want to provide with this class is the ability to "recover" from service failure (i.e. faulted communcation channels) and shutdown. For this purpose I obtain a reference to the service channel and subscribe to the ICommunicationObject.Closed and ICommunicationObject.Faulted events. When these events occur I start a "recovery" procedure that basically attempts to re-establish a connection to the service every few seconds. The assumption is that if the service becomes unavailable, for whatever reason, it will soon become available again and the client application can pick up where it was.

I have two services. Service A requires a callback contract and service B doesn't. Service A uses a duplex channel, service B doesn't. Both require sessions. Service A implicitly creates a session; service B has IsInitiating and IsTerminating operations defined. Here's the (somewhat confusing) behaviour I see:

Service A

  • Graceful shutdown -> the Faulted event is raised and can be handled by the proxy, but not the Closed event.
  • "Hard" shutdown -> same as above.

Service B

  • Graceful shutdown - no event is raised.
  • "Hard" shutdown - no event is raised.

Note that both services use the same proxy class. The only difference is in how they are initialised. Proxy A uses a duplex channel factory and therefore has to create an instance context to which is passed an instance implementing service A's callback contract. Proxy B simply uses a "regular" channel factory.

Any ideas?

Many thanks,
J.

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

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

发布评论

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

评论(1

挽袖吟 2024-10-09 03:14:28

ICommunicationObject.State 属性对您有帮助吗?应返回打开、关闭、故障以及打开和关闭的过渡状态。也许您可以在调用任何方法之前在代理中检查这一点

Would the ICommunicationObject.State property help you here? Should return open, closed, faulted, and also the transitional states opening and closing. Perhaps you can check this within your proxy before you call any methods

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