【发布时间】:2013-12-14 05:24:55
【问题描述】:
我正在尝试使用 WCF 可靠会话来启用从服务到客户端的回调。这个回调通道需要无限期开放。
在某些 .NET 版本中似乎存在一个错误,导致reliable sessions fault prematurely。应该没问题,只需将 inactivityTimeout 和 receiveTimeout 设置为足够高的值(例如TimeSpan.MaxValue)。
但是无论我如何配置我的客户端和服务,通道在 10 分钟后仍然会出现故障,无论我设置的超时值如何。
如果没有我的配置,这个问题将是不完整的,所以这里是:
<!-- service's app.config -->
<!-- irrelevant stuff snipped .. -->
</binding>
<netTcpBinding>
<!-- enable reliable sessions, set timeouts to their maximum possible value!!! -->
<binding name="netTcpReliable" receiveTimeout="infinite">
<reliableSession enabled="true" inactivityTimeout="infinite"/>
</binding>
</netTcpBinding>
</binding>
<services>
<service name="SomeService" behaviorConfiguration="metadataBehavior">
<host>
<baseAddresses>
<add baseAddress="net.tcp://localhost:port/SomeService"/>
</baseAddresses>
</host>
<endpoint name="SomeService_BasicTcpEndpoint"
address="service"
binding="netTcpBinding"
bindingConfiguration="netTcpReliable"
contract="ISomeService" />
</service>
<services>
// client's binding generation code
var binding = new NetTcpBinding(SecurityMode.Transport, true) // enable reliable session
{
OpenTimeout = openCloseTimeout,
CloseTimeout = openCloseTimeout,
SendTimeout = sendTimeout,
ReceiveTimeout = TimeSpan.MaxValue // maximum possible value (infinite in app.config)
};
binding.ReliableSession.InactivityTimeout = TimeSpan.MaxValue; // maximum possible value (infinite in app.config)
var factory = new ChannelFactory<TChannel>(binding);
return factory.CreateChannel(endpointAddress);
因此,如您所见,所有超时都配置为高于 10 分钟的值,并且在没有任何服务调用的情况下,通道在 10 分钟后仍会出现故障。我该如何规避这个?据我了解,可靠会话(除其他外)正是用于此目的:保持通道活动并防止它们出现故障(通过发送基础设施保持活动数据包 - 至少在最近没有 aforementioned bug 的 .NET 版本中)。
【问题讨论】:
-
我意识到这已经快一年了.. 但是您是否在客户端和服务器上都设置了这个值?
标签: wcf timeout channel fault reliablesession