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



我正在创建一个带有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和用于双工消息传递的可靠会话中的inactivityTimeout定义。正确的解决方案不是增加超时,而是实现一些ping/保持活动状态的消息。原因是增加超时将使失败客户端的连接保持打开状态。

您可以发布客户端调用示例(服务调用示例)吗?这里可能发生的情况是您没有正确关闭客户端,并且在服务端达到了最大会话数。
您必须知道,使用 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

最新更新