简体   繁体   English

WCF可靠的会话出错

[英]WCF The Reliable Session Was Faulted

I have a WCF service hosted in a Windows service which publishes errors to any subscribed monitor applications. 我在Windows服务中托管了WCF服务,该服务将错误发布到任何已订阅的监视器应用程序。 There are 2 server applications which publish errors to the service and then these errors are sent to any subscribed monitor applications. 有2个服务器应用程序将错误发布到服务,然后将这些错误发送到任何订阅的监视器应用程序。 This is done using WSDualHttpBinding. 这是使用WSDualHttpBinding完成的。

This works but after a length of inactivity it stops working and brings up an error stating that the reliable session was faulted. 这可以正常工作,但是经过一段时间的不活动后,它会停止工作,并显示一条错误消息,指出可靠的会话有故障。 I have read several articles on this issue but it hasn't helped track it down. 我已经阅读了有关此问题的几篇文章,但并没有帮助您找到答案。 I have put in all neccessary exception handling but this isn't helping. 我已经放入了所有必要的异常处理,但这无济于事。

Rather than post my code, the system is based on the List Based Publish Subscribe sample in the MSDN just with addition error checking and exception handling. 该系统不是基于我的代码,而是基于MSDN中的基于列表的发布订阅示例,仅具有附加的错误检查和异常处理。 Link below. 下方链接。

http://msdn.microsoft.com/en-us/library/ms752254.aspx http://msdn.microsoft.com/en-us/library/ms752254.aspx

Does anyone have any ideas what is causing this? 有谁知道是什么原因造成的?

You're right that you need to increase your inactivity timeout. 没错,您需要增加不活动超时时间。 But when you are using reliable sessions, the receiveTimeout is also taken into account. 但是,当您使用可靠的会话时,也会考虑receiveTimeout。 From this MSDN Article : 从此MSDN文章

When using a reliable session, there are two different inactivity timers that must be satisfied to keep the connection alive. 使用可靠的会话时,必须满足两个不同的不活动计时器以保持连接有效。 If either of these inactivity timers goes off, then the connection is dropped. 如果这些不活动计时器中的任何一个都关闭,则连接断开。

The first inactivity timer is on the reliable session and is called the InactivityTimeout. 第一个不活动计时器位于可靠会话上,称为InactivityTimeout。 This inactivity timer fires if no messages, either application or infrastructure, are received within the timeout period. 如果在超时时间内未收到任何消息(应用程序或基础结构),则此不活动计时器将触发。 An infrastructure message is a message that is generated for the purpose of one of the protocols in the channel stack, such as a keep alive or an acknowledgment, rather than containing application data. 基础结构消息是为了通道堆栈中的一种协议(例如保持活动或确认)而生成的消息,而不包含应用程序数据。

The second inactivity timer is on the service and uses the ReceiveTimeout setting of the binding. 第二个不活动计时器在服务上,并使用绑定的ReceiveTimeout设置。 This inactivity timer fires if no application messages are received within the timeout period. 如果在超时时间内未收到任何应用程序消息,则此不活动计时器将触发。 This specifies, for example, the maximum time a client may take to send at least one message to the server before the server will close the channel used by a session. 例如,这指定了在服务器关闭会话使用的通道之前,客户端向服务器发送至少一条消息所花费的最长时间。 This behavior ensures that clients cannot hold on to server resources for arbitrary long periods. 此行为可确保客户端无法长时间任意占用服务器资源。

Since the connection is dropped if either inactivity timer fires, increasing InactivityTimeout once it is greater than ReceiveTimeout has no effect. 由于如果其中一个不活动计时器触发,则连接将被丢弃,因此,一旦InactivityTimeout大于ReceiveTimeout,则增加它无效。 The default for both of these timeouts is 10 minutes, so you always have to increase both of them to make a difference when using a reliable session. 这两个超时的默认值都是10分钟,因此在使用可靠的会话时,您总是必须增加两个超时值才能有所作为。

Setting both of these values to "Infinite" (if you're using config files) or TimeSpan.MaxValue if you're setting your bindings up in code should achieve what you're looking for. 将这两个值都设置为“ Infinite”(如果使用配置文件)或将TimeSpan.MaxValue设置为在代码中设置绑定都可以实现所需的功能。

EDIT 1 Setting the receiveTimeout and inactivityTimeout values to "infinite" will generate a warning in the compiler. 编辑1将receiveTimeout和inactivityTimeout值设置为“ infinite”将在编译器中生成警告。 This is okay. 没关系 The IDE uses an XSL that doesn't take that keyword into account. IDE使用的XSL不考虑该关键字。 Behind the scenes, WCF is using a TimeSpanOrInfiniteConverter to convert the keyword to TimeSpan.MaxValue. 在幕后,WCF使用TimeSpanOrInfiniteConverter将关键字转换为TimeSpan.MaxValue。 Source 资源

I seemed to have fixed this but all I have done is change the binding from WSDualHTTPBinding to NetTcpBindng. 我似乎已解决此问题,但我所做的只是将绑定从WSDualHTTPBinding更改为NetTcpBindng。 It's now been running for 48 hours whereas before it wouldn't run for more than an hour. 它已经运行了48个小时,而在此之前已经运行了一个多小时。

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

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