简体   繁体   English

WCF TCP双工绑定配置的发布/订阅模式

[英]Publish/Subscribe Pattern for WCF TCP Duplex Binding Configuration

I have a WCF configuration dilemma when using WCF TCP Binding for Duplex Callbacks as part of a Publish/Subscribe design pattern. 将WCF TCP绑定用于双工回调作为发布/订阅设计模式的一部分时,我遇到WCF配置难题。

The requirement is for the Client to receive notifications from the Server using one-way callbacks. 要求客户端使用单向回调从服务器接收通知。 It is unknown when the notifications will be received therefore the aim is to keep the connection open indefinitely. 何时接收到通知尚不清楚,因此目的是无限期地保持连接打开。 If an exception is received by either the Client or Server then the cleanup process is initiated to correctly Close, Abort and cleanup the CommunicationObject and then issue a new connection to continue receiving notifications. 如果客户端或服务器接收到异常,则将启动清理过程以正确关闭,中止和清理CommunicationObject,然后发出新连接以继续接收通知。

I have explicit access to configure both the Client and Server WCF endpoints. 我具有显式访问权限,可以同时配置客户端和服务器WCF端点。 My dilemma is whether I should: 我的困境是我是否应该:

A. Keep the sendTimeout and receiveTimeout configuration properties set to infinite to keep the connections open as long as possible whilst still handling exceptions to reopen the connection. A.保持sendTimeoutreceiveTimeout配置属性设置为infinite以保持连接尽可能长的打开,同时仍处理异常以重新打开连接。

Or 要么

B. Keep the sendTimeout and receiveTimeout to a lower time span, for example 1 hour. B.保持sendTimeoutreceiveTimeout较低的时间范围,例如1小时。 The timeouts would be received by the client or server, cleaned up, and then a new connection established. 超时将由客户端或服务器接收,清理,然后建立新的连接。

Would there be an advantage of using one over the other or is WCF not a viable solution for my problem? 使用WCF而不是使用WCF是否对我的问题而言不是可行的解决方案?

My aim is to maintain the highest availability possible. 我的目标是保持最高的可用性。

EDIT: 编辑:

The reason why I was concerned about the timeouts was that the server is unexpectedly closing or timing-out the connection without the client receiving any notifications of this through either the Faulted and Closing events, but I can confirm that both the client and server are both using infinite timeouts for sendTimeout and receiveTimeout . 我担心超时的原因是服务器意外关闭或超时连接,而客户端没有通过FaultedClosing事件接收到任何有关此操作的通知,但是我可以确认客户端和服务器都是为sendTimeoutreceiveTimeout使用无限超时。 This normally happens within a 24 hour time scope. 这通常在24小时内发生。

Researching the MSDN documentation for a WCF Duplex model I read the following statement: 研究WCF双工模型的MSDN文档时,我读了以下语句:

The duplex model does not automatically detect when a service or client closes its channel. 双工模型不会自动检测服务或客户端何时关闭其通道。 So if a client unexpectedly terminates, by default the service will not be notified, or if a client unexpectedly terminates, the service will not be notified. 因此,如果客户端意外终止,则默认情况下不会通知服务,或者如果客户端意外终止,则不会通知服务。 Clients and services can implement their own protocol to notify each other if they so choose. 客户端和服务可以选择使用自己的协议来相互通知。

Which brings me on to ask whether anyone has a solution for implementing their own protocol for keeping a session alive as this is the problem I have? 这就带我问一个问题,是否有人可以实现自己的协议以保持会话存活,因为这是我的问题?

Do I need to simply have a client thread which sends a "heartbeat" to the server on a regular time interval? 我是否只需要有一个客户端线程,该线程会在固定的时间间隔内将“心跳”发送到服务器? Obviously I don't want to spam the network with heartbeats, but at the same time keep the session alive as much as possible. 显然,我不想通过心跳向网络发送垃圾邮件,但同时尽可能使会话保持活动状态。

I believe a ReliableSession would provide no real benefit to this problem. 我相信ReliableSession不会为这个问题带来任何实际好处。

I think you should just keep receiveTimeout as infinite and that's it. 我认为您应该仅将receiveTimeout保持为infinite ,就是这样。 There is no bonus of recreating a channel every hour. 每小时重新创建一个频道没有任何好处。

You do not need to set sendTimeout to infinite because this is a timeout that defines for how long WCF infrastructure waits before claims that it cannot send a message. 您不需要将sendTimeout设置为infinite因为这是一个超时,它定义了WCF基础结构在无法发送消息的声明之前要等待的时间。

PS In our application we use similar technique and channel is kept opened for weeks without any problems. PS在我们的应用程序中,我们使用类似的技术,并且通道保持打开状态数周没有任何问题。

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

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