禁用WCF net.tcp绑定的连接池

时间:2012-03-15 05:25:08

标签: wcf net.tcp

我有一个特定的场景,我需要禁用net.tcp连接池。我意识到这不是一个理想的配置,但是我需要在我的特定环境中暂时解决问题。

任何人都可以提供一个禁用连接重用\池的net.tcp绑定配置示例吗?

1 个答案:

答案 0 :(得分:0)

以下是我在代码中的表现。

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

http://msdn.microsoft.com/en-us/library/ms788984.aspx