In message Http header of BasicHttpBinding the Keep-Alive value is true by default which helps to keep persistent connections into services to reuse by sending messages to the same server that improves performance of services. The side effect is the cause of associating clients to specific server which reduces the effectiveness of load balancing. Setting KeepAliveEnabled value to false within a CustomBinding allows NLB functions correctly without sticky session and server affinity.
using (var srv = new SrvClient("BasicHttpLB"))
{
#region Custom binding to disable [Keep Alive] property of transport Element
var wcfsrvCstmBndng = new CustomBinding(svcBinding);
var bindingTransportElement =
wcfsrvCstmBndng.Elements.Find< HttpTransportBindingElement>();
bindingTransportElement.KeepAliveEnabled = false;
// Disable [Keep Alive] property of Transport Element
#endregion
srv.Endpoint.Binding = wcfsrvCstmBndng;
.... //Calling service operations and do what's necessary
}
No comments:
Post a Comment