I also needed to set this property in the code, and after researching, he found that there are two ways to do this programmatically.
The first way is to create anchor elements directly in the code and create a new custom anchor from them, as described in CustomBinding MSDN
// Create a custom binding that contains two binding elements. ReliableSessionBindingElement reliableSession = new ReliableSessionBindingElement(); reliableSession.MaxPendingChannels = 100; TcpTransportBindingElement tcpTransport = new TcpTransportBindingElement(); CustomBinding binding = new CustomBinding(reliableSession, tcpTransport);
the second method I found is to grab the link to the binding elements from an existing binding, as described here How to configure binding to the system . This is the best answer.
I tried to set the ReliableSession property to NetTcpBinding, but actually it did not change the MaxPendingConnections property that I was expecting. After examining the .NET source for NetTcpBinding and ReliableSession, I found that setting this property in a binding like this
NetTcpBinding netTcpBinding = new NetTcpBinding(SecurityMode.None, true); netTcpBinding.ReliableSession = new OptionalReliableSession( new ReliableSessionBindingElement() { MaxPendingChannels = 100 });
Actually, the MaxPendingChannels property for binding is not set.
In the end, I created the binding to the binding elements, since I wanted to precisely control the binding
source share