【问题标题】:WCF reliable session faults regardless of configured timeouts无论配置的超时如何,WCF 可靠会话故障
【发布时间】: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


【解决方案1】:

您应该在编译期间收到警告,指出无限不是超时的合法值。 最长超时时间约为 24 天。

【讨论】:

  • 从技术上讲,有一个特殊的配置序列化程序将无限解释为 TimeSpan.MaxValue,但即便如此,他还是用 MaxValue 覆盖了代码中的值,所以你的评论不是很有帮助。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-06-09
  • 2020-02-21
  • 2016-01-28
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多