As the question says. At the moment we’re caching the WCF client proxy (ChannelFactory to be precise) to our services per session. This works fine. But now we’ve moved to Azure, and there are multiple instances (of session). I got AppFabric session state working now. So the session is provided by Azure, but now the problem is with caching of the channel factory. Because the factory is not [Serializable] and therefore it seems cannot be stored in the Session[]. What are the options? Should the channel be recreated every time the WCF service method is being called?
[ 1. previous working state; 2. newly attempted solution; 3. fall-back option ]
- WCF Client -> ASP.NET -> Session cached factory -> Channel -> WCF Service
- WCF Client -> ASP.NET -> Cannot store factory! -> Channel -> Azure role WCF Service
- WCF Client -> ASP.NET -> New channel each call -> Azure role WCF Service
Update: We’ve established, that it won’t be possible to cache (share) the ChannelFactory. So the question remains, how can I share the credentials (UserNameCredentials) which are therefore not being shared now, and somehow have to be distributed across the split instances. The obvious option is to store the encrypted credentials in a cache? Is it a good idea? Is there any other way to do it?
This continues as a new question: How to share WCF client credentials…
If you want to cache the ChannelFactory, you are going to need to have one per session per azure role instance. You are correct that CacheFactories should not be shared across sessions as they may be supporting different users.
As you’ve rightly said, a CacheFactory is not serializable, so you’re not going to be able to put it into the distributed cache.
Half the reason to cache it is to avoid the set-up time for the CacheFactory (may be many 10’s of milliseconds). Serializing it into and out of the cache may be even longer than that as the CacheFactory is fairly large in size.