Showing posts with label WCF. Show all posts
Showing posts with label WCF. Show all posts

Monday, September 30, 2013

WCF Load Balancing – basicHttpBinding

To enable WCF service to take advantage of Load balancing with basicHttpBinding easily it needs to set keepAliveEnabled property of binding to false when there is connection reuse. When this property is enabled, will lead a client to maintain a persistent connection with the service which helps for performance side of view as the connection reuses with multiple messages. Ideally in a load balanced cluster the purpose is to avoid having sticky sessions and strongly associated a client with a server, a simple solution is utilizing the following configuration for custom binding:

<customBinding> <binding name="CustomHttpBindingConfig" closeTimeout="00:10:00" openTimeout="00:10:00" sendTimeout="00:10:00"> <textMessageEncoding /> <httpTransport keepAliveEnabled="false" /> </binding> </customBinding>


Another approach to apply necessary changes through the code discussed before in “WCF service under Network Load Balancing (NLB)” blog entry.

Share/Bookmark

Tuesday, August 6, 2013

WCF service under Network Load Balancing (NLB)

To use WCF services on multi servers under Network Load Balancing one solution would be utilizing BasicHttpBinding as WCF channels that use this binding are inherently stateless, and terminate their connections when the channel closes.

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 }

Share/Bookmark