ChannelFactory Caching in WCF 4.5

ChannelFactory is a factory class for creating the channel instances in a WCF client.
This class simplifies the task of creating the channel between a WCF service and a client.
When an instantiation is done on the client it means a channel is established with the WCF service and creates the proxy of the service for further communications like that of a method call.
A channel will be created over an address, binding and contract (service endpoint) combination.


The channel will be created while creating the channel instance, it also takes a certain amount or resource overhead for achieving it on the fly.
Prior to the .NET Framework 4.5 developers had to implement a custom channel factory caching mechanism but now Microsoft has introduced in build caching for ChannelFactory.
WCF proxy, which is generated inherit from the class named ClientBase and this class holds the property names CacheSettings to hold the caching configuration for the ChannelFactory.
Also the creation of the channel will be wrapped under the ClientBase creation.

ClientBase<IClientChannel>.CacheSetting = CacheSetting.AlwaysOn;

There are three modes of ChannelFactory caching available.

This mode will allow the developer to make the ChannelFactory to be cached always no matter if the endpoint or other security –sensitive properties are updated.
The developer should have done proper analysis so that using this mode wouldn’t affect the service calls in any means.

The Default mode will cache the ChannelFactory object and use it until any of the client’s security sensitive properties are accessed.
The security sensitive properties are Endpoint, ClientCredentials and the ChannelFactory.

ChannelFactory is never cached and the instance is always newly created.

© 2015, www.techkatak.com. All rights reserved.