“A ChannelFactory basically creates a Channel for WCF clients to communicate with WCF service endpoint“.
- New Features in WCF 4.5 – Part 1
- Simplified Generated Configuration
- Validating WCF Configuration
- New Features in WCF 4.5 – Part 2
- Single WSDL file
- Tooltip and Intellisense Support
- New Features in WCF 4.5 – Part 3
- ASP.NET Compatibility Mode default change
- BasicHttpsBinding
- New Features in WCF 4.5 – Part 4
- Task-based Programming Model
Using ChannelFactory is a good option, if we have control over Client as well as Server because in case of ChannelFactory, we have local interfaces (WCF Contract) on client to describe our WCF service.
{
BasicHttpBinding cacheTestBinding = new BasicHttpBinding();
EndpointAddress cacheTestEndpoint = new
EndpointAddress(“http://localhost:XXX/CacheTestService.svc”);
ChannelFactory cacheTestChannelFac = new
ChannelFactory(cacheTestBinding, cacheTestEndpoint);
var objChannel = cacheTestChannelFac.CreateChannel();
Console.WriteLine(objChannel.MethodA());
objChannel.Close();
}
Now with WCF 4.5, built-in support available for ChannelFactory Cache through CacheSetting property of ClientBase<T> class. Possible values of CacheSetting property are:
- System.ServiceModel.CacheSetting.AlwaysOn
- System.ServiceModel.CacheSetting.Default
- System.ServiceModel.CacheSetting.AlwaysOff
Caching is always ON meaning all instances of ClientBase within same app-domain will be using sameChannelFactory.
CacheSetting.AlwaysDefault:
With default means that only instances of ClientBasecreated from configuration file endpoint will participate in caching. Others created programmatically will not participate. Also condition of same app-domain is also applicable here.
CacheSetting.AlwaysOff:
No caching for all instances of ClientBase<TChannel>.
Undoubtedly, this new feature in Windows Communication Foundation v4.5 is really helpful for WCF developers to manage support for caching ChannelFactory instances.
Top 10 Interview Questions and Answers Series:
- Top 10 WCF Interview Questions
- Comprehensive Series of WCF Interview Questions
- Top 10 HTML5 Interview Questions
- Top 10 ASP.NET Interview Questions
- Comprehensive Series of ASP.NET Interview Questions
- Top 10 ASP.NET MVC Interview Questions
- Top 10 ASP.NET Web API Interview Questions
- Top 10 ASP.NET AJAX Interview Questions