title: C# WCF NetTcpBinding timeout not working
body: <p>I've got a problem with the NetTcpBinding's Open, Send, Recive and Close timeouts on the initial call(<code>[OperationContract(IsOneWay = true, IsInitiating = true)]</code>)
  Currently I'm trying to connect to a given IPAddress and if it fails I will connect to a different address.
  This is because I cannot connect to my own server through my external IP (due to NAT Loopback on my router?), and instead of having 2 versions (one for the public and one for myself) I use a Try-Catch system which tries to connect to my external IP, if it works -> continue, if it fails -> try local IP -> continue.</p>
  
  <p>The problem however is the timeout values. Since I am waiting for an exception to be thrown and caught, I need to lower this value as much as possible (preferred 5sec) instead of the default ~20 seconds.</p>
  
  <p>I've tried to set these values on both Client and Server side</p>
  
  <pre><code>tcpBinding.OpenTimeout = new TimeSpan(0, 0, 5);
  tcpBinding.CloseTimeout = new TimeSpan(0, 0, 5);
  tcpBinding.SendTimeout = new TimeSpan(0, 0, 5);
  tcpBinding.ReceiveTimeout = new TimeSpan(0, 0, 5);
  </code></pre>
  
  <p><strong>Server side setup:</strong></p>
  
  <pre><code>svh = new ServiceHost(typeof(ServiceAssembly.ServiceImplementation));
  NetTcpBinding tcpBinding = new NetTcpBinding();
  
  tcpBinding.MaxConnections = 100;
  tcpBinding.MaxBufferPoolSize = (int)4096000;
  tcpBinding.MaxBufferSize = 4096000;
  tcpBinding.MaxReceivedMessageSize = (int)4096000;
  tcpBinding.OpenTimeout = new TimeSpan(0, 0, 5);
  tcpBinding.CloseTimeout = new TimeSpan(0, 0, 5);
  tcpBinding.ReceiveTimeout = new TimeSpan(0, 0, 5);
  tcpBinding.SendTimeout = new TimeSpan(0, 0, 5);
  tcpBinding.ReliableSession.Ordered = true;
  tcpBinding.TransactionFlow = false;
  tcpBinding.Security.Transport.ProtectionLevel =
  System.Net.Security.ProtectionLevel.EncryptAndSign;
  tcpBinding.Security.Transport.ClientCredentialType =
  TcpClientCredentialType.Windows;
  tcpBinding.Security.Mode = SecurityMode.None;
  
  svh.AddServiceEndpoint(typeof(ServiceAssembly.IChat),tcpBinding,"net.tcp://IPAddress:3100/MyService");
  
  SynchronizationContext.SetSynchronizationContext(new SynchronizationContext());
  svh.Open();
  </code></pre>
  
  <p><strong>Client side setup &amp; call</strong></p>
  
  <pre><code>InstanceContext context = new InstanceContext(callback);
  NetTcpBinding tcpBinding = new NetTcpBinding();
  
  tcpBinding.MaxConnections = 100;
  tcpBinding.MaxBufferPoolSize = (int)4096000;
  tcpBinding.MaxBufferSize = 4096000;
  tcpBinding.MaxReceivedMessageSize = (int)4096000;
  tcpBinding.TransactionFlow = false;
  tcpBinding.OpenTimeout = new TimeSpan(0, 0, 5);
  tcpBinding.CloseTimeout = new TimeSpan(0, 0, 5);
  tcpBinding.SendTimeout = new TimeSpan(0, 0, 5);
  tcpBinding.ReceiveTimeout = new TimeSpan(0, 0, 5);
  tcpBinding.ReliableSession.Ordered = true;
  
  tcpBinding.Security.Transport.ProtectionLevel =
      System.Net.Security.ProtectionLevel.EncryptAndSign;
  tcpBinding.Security.Transport.ClientCredentialType =
      TcpClientCredentialType.Windows;
  tcpBinding.Security.Mode = SecurityMode.None;
  
   try
   {
        scf = new DuplexChannelFactory&lt;IChat&gt;(context, tcpBinding,
              "net.tcp://" + m_ipAddress + ":" + m_port + "/MyService");
        s = scf.CreateChannel(); 
        s.Connect(client); &lt;- First connection
   }
   catch
   {
       try
       {
           scf = new DuplexChannelFactory&lt;IChat&gt;(context, tcpBinding,
                 "net.tcp://" + m_localAddress + ":" + m_port + "/MyService");
           s = scf.CreateChannel();
           s.Connect(client);
           m_ipAddress = m_localAddress;
       }
       catch (Exception ex)
       {
           MessageBox.Show(ex.Message);
       }
   }
  </code></pre>
  
  <p>But the timeout for the exception to be thrown is still around 20 seconds. Changing these values wont change the time until the exception is thrown. I have added an image below to show the call stack.
  <a href="https://i.stack.imgur.com/YSEix.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/YSEix.png" alt="enter image description here"></a>
  Any advice on how to do fix this or even make it better is wanted.</p>