5

I'm creating a chat application with WCF(using callback contract) and netTcpBinding. I'm hosting the service as a windows service and accessing it from other computers via the client application.

The problem that i'm facing now is the clients connection comes to a Fault state after 10 mins which seems to be some kind of timeout that occur. I already tried increasing the received timeout and send timeout in both service and client but didn't work.

which setting should i change to increase this timeout period and in which application, service or client?

Following are my configuration files,

Service

    <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>

Client

<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>

Thanks.

user501579
  • 251
  • 1
  • 8
  • 14
  • have you tried setting receiveTimeout to -1. http://msdn.microsoft.com/en-us/library/ms824661.aspx. called infinity – Shoaib Shaikh Apr 16 '12 at 07:15
  • try this as well http://nogeekhere.blogspot.com/2009/04/why-will-wcf-client-be-disconnected.html – Shoaib Shaikh Apr 16 '12 at 07:15
  • Thanks Shoaib, I tried using infinite but didn't accept as a valid value in the config file. any reason for that? any ways, i did a small workaround so that the service will refresh each client every 5 mins. But I guess there should be a way to handle this through configurations. – user501579 Apr 16 '12 at 09:11

2 Answers2

4

The timeout in this case is defined by both receiveTimeout in the binding and inactivityTimeout in reliable session which is used for duplex messaging. The correct solution is not increasing timeout but implementing some ping / keep alive messages. The reason is that increasing timeout will keep connections open for failed clients.

Ladislav Mrnka
  • 360,892
  • 59
  • 660
  • 670
  • WCF may provide its own keepalive messaging though, but Im not sure what values need to used and if this has changed since 2009?: "According to the documentation a Reliable Session would send a keep-alive message after half of the Inactivity Timeout. Unfortunately the expected behaviour was not the same as the actual behaviour.. the Receive Timeout behaviour overrode the keep-alive behaviour" http://smartasses.be/2009/01/26/wcf-reliable-session-and-keep-alives – Cel Jan 04 '14 at 09:18
1

Can you post client call sample (service call example). What might happening here is that you are not closing client correctly and you reach maximum sessions on service side.
You must be aware that using net.tcp binding is different than http.

You can use System.ServiceModel performance counters (http://msdn.microsoft.com/en-us/library/ms750527.aspx) and see after 10 minutes what is happening (number of calls outstanding, number of service instances, etc..)

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

Milan Svitlica
  • 645
  • 4
  • 9