Load Balancing WCF – basicHttpBinding

Load balancing WCF with basicHttpBinding can be done using the keepAliveEnabled property when there is connection reuse. Basically this property when enabled, enables a client to maintain a persistent connection with the service and gives enhanced throughput with connection reuse with multiple messages. But in a load balanced farm we cannot have a client strongly associated with a server and so need to disable this property.

This can be accessed through a custom binding as follows.



                <binding name=NewBinding0>

                    <textMessageEncoding />

                    <httpTransport keepAliveEnabled=false />




If you are interested in TCP load balancing check out this post by [Kenny]
This article should give you more information MSDN


BindingElementCollection bec = new BasicHttpBinding().CreateBindingElements();bec.Find<HttpTransportBindingElement>().KeepAliveEnabled = false;CustomBinding cb = new CustomBinding(bec);