Freigeben über


How to change the IdleTimeout/LeaseTimeout on NetTcpBinding?

To modify properties that are not exposed on the standard binding we can create a CustomBinding from the provided standard binding. We can then find the element required on the particular CustomBinding and tweak it. Another option would be to just hand craft the full standard binding if you know exactly how to stack up the elements. Here is an example to how to tweek the IdleTimeout.

 private static CustomBinding GetIdleBinding(int mins)
{
    NetTcpBinding tcpBinding = new NetTcpBinding();
    CustomBinding customBinding = new CustomBinding(tcpBinding);
    TcpTransportBindingElement transport = customBinding.Elements.Find();
    transport.ConnectionPoolSettings.IdleTimeout = TimeSpan.FromMinutes(mins);
    return customBinding;
}