使用netTcp绑定的WCF回调服务在10分钟后超时

5
我正在使用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 吗?http://msdn.microsoft.com/en-us/library/ms824661.aspx。称之为无限。 - Shoaib Shaikh
也可以尝试访问这个链接:http://nogeekhere.blogspot.com/2009/04/why-will-wcf-client-be-disconnected.html - Shoaib Shaikh
谢谢Shoaib,我尝试使用"infinite"作为配置文件中的有效值,但是系统不接受。有什么原因吗?无论如何,我做了一个小的变通,使得服务每5分钟刷新一次客户端。但我想应该有一种通过配置来处理这个问题的方法。 - user501579
2个回答

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

WCF可能提供自己的保持活动消息,但我不确定需要使用哪些值,以及自2009年以来是否发生了更改?根据文档,可靠会话在不活动超时的一半后发送保持活动消息。不幸的是,预期行为与实际行为不同...接收超时行为覆盖了保持活动行为。http://smartasses.be/2009/01/26/wcf-reliable-session-and-keep-alives - Cel

1

你能否发布客户端调用样例(服务调用示例)?这里可能发生的是您没有正确关闭客户端,从而在服务端达到了最大会话数。
您必须意识到使用 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


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接