【问题标题】:WCF Callback Service with netTcp Binding timeout after 10 mins10 分钟后具有 netTcp 绑定超时的 WCF 回调服务
【发布时间】:2012-04-16 06:25:53
【问题描述】:

我正在使用 WCF(使用回调协定)和 netTcpBinding 创建一个聊天应用程序。 我将该服务托管为 Windows 服务并从其他计算机访问它 通过客户端应用程序。

我现在面临的问题是客户端连接在之后进入故障状态 10 分钟,这似乎是某种超时发生。 我已经尝试在服务和客户端中增加接收超时和发送超时,但没有奏效。

我应该更改哪个设置以增加此超时时间以及在哪个应用程序、服务或客户端中?

以下是我的配置文件,

服务

    <system.serviceModel>
    <services>
      <service behaviorConfiguration="PeerTalk.Service.ChatServiceBehavior"
        name="PeerTalk.Service.ChatService">
        <endpoint address="" binding="netTcpBinding" bindingConfiguration=""
          contract="PeerTalk.Service.ServiceContracts.IChat">
          <identity>
            <dns value="localhost" />
          </identity>
        </endpoint>
        <endpoint address="mex" binding="mexTcpBinding" bindingConfiguration=""
          contract="IMetadataExchange" />
        <host>
          <baseAddresses>
            <add baseAddress="http://localhost:7920/ChatService" />
            <add baseAddress="net.tcp://localhost:7921/ChatService" />
          </baseAddresses>
        </host>
      </service>
    </services>
    <behaviors>
      <serviceBehaviors>
        <behavior name="PeerTalk.Service.ChatServiceBehavior">
          <serviceMetadata httpGetEnabled="false" />
          <serviceDebug includeExceptionDetailInFaults="false" />
        </behavior>
      </serviceBehaviors>
    </behaviors>
    <bindings>
      <netTcpBinding>
        <binding name="tcpBinding"
                 maxBufferSize="67108864"
           maxReceivedMessageSize="67108864"
           maxBufferPoolSize="67108864"
           transferMode="Buffered"
           closeTimeout="00:01:00"
           openTimeout="00:01:00"
           receiveTimeout="00:00:10"
           sendTimeout="00:00:10"
           maxConnections="100">
          <readerQuotas maxDepth="64"
                        maxStringContentLength="67108864"
                        maxArrayLength="67108864"
                        maxBytesPerRead="67108864"
                        maxNameTableCharCount="16384"/>
          <security mode="Transport">
            <transport clientCredentialType="Windows" protectionLevel="EncryptAndSign" />
            <message clientCredentialType="Windows"/>
          </security>
          <reliableSession enabled="false" inactivityTimeout="00:01:00"/>

        </binding>
      </netTcpBinding>
    </bindings>
  </system.serviceModel>

客户

<system.serviceModel>
    <bindings>
      <netTcpBinding>
        <binding name="NetTcpBinding_IChat" closeTimeout="00:01:00" openTimeout="00:01:00"
          receiveTimeout="00:10:00" sendTimeout="00:00:10" transactionFlow="false"
          transferMode="Buffered" transactionProtocol="OleTransactions"
          hostNameComparisonMode="StrongWildcard" listenBacklog="10" maxBufferPoolSize="67108864"
          maxBufferSize="67108864" maxConnections="10" maxReceivedMessageSize="67108864">
          <readerQuotas maxDepth="32" maxStringContentLength="67108864"
            maxArrayLength="67108864" maxBytesPerRead="67108864" maxNameTableCharCount="16384" />
          <reliableSession ordered="true" inactivityTimeout="00:01:00"
            enabled="false" />
          <security mode="Transport">
            <transport clientCredentialType="Windows" protectionLevel="EncryptAndSign" />
            <message clientCredentialType="Windows" />
          </security>
        </binding>
      </netTcpBinding>
    </bindings>
    <client>     
          <endpoint address="net.tcp://10.10.10.45:7921/ChatService" binding="netTcpBinding"
               bindingConfiguration="NetTcpBinding_IChat" contract="PeerTalkService.IChat"
               name="NetTcpBinding_IChat">
          </endpoint>
    </client>
  </system.serviceModel>

谢谢。

【问题讨论】:

  • 您是否尝试过将 receiveTimeout 设置为 -1。 msdn.microsoft.com/en-us/library/ms824661.aspx。称为无穷
  • 感谢 Shoaib,我尝试使用无限但不接受配置文件中的有效值。有什么理由吗?无论如何,我做了一个小解决方法,以便该服务每 5 分钟刷新一次每个客户端。但我想应该有办法通过配置来处理这个问题。

标签: wcf wcf-callbacks


【解决方案1】:

这种情况下的超时时间由绑定中的receiveTimeout 和用于双工消息传递的可靠会话中的inactivityTimeout 定义。正确的解决方案不是增加超时,而是实施一些 ping / keep alive 消息。原因是增加超时将使失败的客户端保持连接打开。

【讨论】:

  • WCF 可能会提供自己的 keepalive 消息,但我不确定需要使用哪些值以及自 2009 年以来是否发生了变化?:“根据文档,Reliable Session 将发送 keep-alive 消息在不活动超时的一半之后。不幸的是,预期行为与实际行为不同。接收超时行为覆盖了保持活动行为“smartasses.be/2009/01/26/wcf-reliable-session-and-keep-alives
【解决方案2】:

您能否发布客户呼叫示例(服务呼叫示例)。这里可能发生的情况是您没有正确关闭客户端,并且您在服务端达到了最大会话数。
您必须知道使用 net.tcp 绑定与 http 不同。

您可以使用 System.ServiceModel 性能计数器 (http://msdn.microsoft.com/en-us/library/ms750527.aspx) 并在 10 分钟后查看发生了什么(未完成的调用数、服务实例数等。)

http://dkochnev.blogspot.com/2011/06/wcf-framework-40-monitoring-service.html

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-10-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-27
    • 1970-01-01
    相关资源
    最近更新 更多