【发布时间】:2012-03-15 05:25:08
【问题描述】:
我有一个特定的场景需要禁用 net.tcp 连接池。我意识到这不是一个理想的配置,但是我需要暂时这样做以解决我特定环境中的问题。
谁能提供一个禁用连接重用\池化的 net.tcp 绑定配置示例?
【问题讨论】:
我有一个特定的场景需要禁用 net.tcp 连接池。我意识到这不是一个理想的配置,但是我需要暂时这样做以解决我特定环境中的问题。
谁能提供一个禁用连接重用\池化的 net.tcp 绑定配置示例?
【问题讨论】:
这是我在代码中的做法。
NetTcpBinding tbinding = new NetTcpBinding(SecurityMode.None, true);
// set some stuff on the binding ...
// ...
BindingElementCollection bElementCol = tbinding.CreateBindingElements();
TcpTransportBindingElement transport = bElementCol.Find<TcpTransportBindingElement>();
transport.ConnectionPoolSettings.IdleTimeout = TimeSpan.Zero;
transport.ConnectionPoolSettings.LeaseTimeout = TimeSpan.Zero;
transport.ConnectionPoolSettings.MaxOutboundConnectionsPerEndpoint = 0;
CustomBinding customBinding = new CustomBinding();
customBinding.Elements.AddRange(bElementCol.ToArray());
customBinding.Name = "NetTcpBinding";
// use customBinding instead of tbinding
这里有一些对我有帮助的链接:
How to set the leaseTimeout setting programmaticaly?
http://plainoldstan.blogspot.ca/2007/09/nettcpbinding-to-custombinding.html
【讨论】: