How to set the leaseTimeout setting programmaticaly?

六月ゝ 毕业季﹏ 提交于 2020-01-17 05:10:09

问题


We have a WCF service (NetTcpBinding) that sits behind a load balancer. I've read that in order to avoid "stickyniss" I have lower the LeaseTime the channels get in the channel pool.

I've only found samples how to set this value using the config file, but I would like to set it programmaticaly, any pointers?


回答1:


You can access the LeaseTimeout property via the TcpTransportBindingElement, through the ConnectionPoolSettings property:

TcpTransportBindingElement tcpBE = new TcpTransportBindingElement();
tcpBE.ConnectionPoolSettings.LeaseTimeout = TimeSpan.FromSeconds(1);

If you have a NetTcpBinding object, you'll need to first convert it into a CustomBinding, then access the binding element. The example below shows one way of doing this.

NetTcpBinding myOriginalBinding = CreateBinding();
CustomBinding newBinding = new CustomBinding(myOriginalBinding);
TcpTransportBindingElement tcpBE = newBinding.Elements.Find<TcpTransportBindingElement>();
tcpBE.ConnectionPoolSettings.LeaseTimeout = TimeSpan.FromSeconds(1);


来源:https://stackoverflow.com/questions/7388179/how-to-set-the-leasetimeout-setting-programmaticaly

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!