Created
March 17, 2015 10:35
-
-
Save a-h/1991902e849ddfa26e29 to your computer and use it in GitHub Desktop.
How to get better performance when creating WCF clients using ChannelFactory<T>
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private static void RegisterServices(IKernel kernel) | |
{ | |
// The ProxyGenerator is part of Castle and will emit code at runtime. This code needs to be cached | |
// or there will be zero improvement in performance. It's cached by default, per instance of the | |
// ProxyGenerator. | |
kernel.Bind<ProxyGenerator>() | |
.ToConstant(new ProxyGenerator()); | |
// The ChannelFactoryCache will cache the creation of the ChannelFactory, which is slow because it | |
// requires the use of reflection. | |
ChannelFactoryCache.Add<IWebServiceInterface>(endpoint, GetBinding(endpoint), null); | |
// Setup Ninject to provide instances of a dynamically generated class which will create instances of | |
// a WCF channel on the fly. See the ToWcfClient extension method. | |
kernel.Bind<IWebServiceInterface>() | |
.ToWcfClient(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment