WCF ChannelFactory caching
Posted
by Myles J
on Stack Overflow
See other posts from Stack Overflow
or by Myles J
Published on 2010-01-21T05:46:43Z
Indexed on
2010/03/24
21:03 UTC
Read the original article
Hit count: 1522
wcf
|channelfactory
I've just read this great article on WCF ChannelFactory caching by Wenlong Dong.
My question is simply how can you actually prove that the ChannelFactory is in fact being cached between calls? I've followed the rules regarding the ClientBase’s constructors. We are using the following overloaded constructor on our object that inherits from ClientBase:
ClientBase(string endpointConfigurationName, EndpointAddress remoteAddress);
In the article mentioned above it is stated that:
For these constructors, all arguments (including default ones) are in the following list:
· InstanceContext callbackInstance
· string endpointConfigurationName
· EndpointAddress remoteAddress
As long as these three arguments are the same when ClientBase is constructed, we can safely assume that the same ChannelFactory can be used. Fortunately, String and EndpointAddress types are immutable, i.e., we can make simple comparison to determine whether two arguments are the same. For InstanceContext, we can use Object reference comparison. The type EndpointTrait is thus used as the key of the MRU cache.
To test the ChannelFactory cache theory we are checking the Hashcode in the ClientBase constructor e.g. var testHash = RuntimeHelpers.GetHashCode(base.ChannelFactory);
The hash value is different between calls which makes us think that the ChannelFactory isn't actually cached.
Any thoughts?
Regards
Myles
© Stack Overflow or respective owner