简体   繁体   English

在Azure上的ASP.NET中缓存WCF ChannelFactory或客户端代理吗?

[英]Caching WCF ChannelFactory or client proxy in ASP.NET on Azure?

As the question says. 正如问题所说。 At the moment we're caching the WCF client proxy (ChannelFactory to be precise) to our services per session. 目前,我们正在将WCF客户端代理(准确地说是ChannelFactory)缓存到每个会话的服务中。 This works fine. 这很好。 But now we've moved to Azure, and there are multiple instances (of session). 但是现在我们已移至Azure,并且有多个(会话)实例。 I got AppFabric session state working now. 我现在正在使用AppFabric会话状态。 So the session is provided by Azure, but now the problem is with caching of the channel factory. 因此,会话是由Azure提供的,但是现在问题出在通道工厂的缓存上。 Because the factory is not [Serializable] and therefore it seems cannot be stored in the Session[]. 由于工厂不是[Serializable],因此似乎无法将其存储在Session []中。 What are the options? 有什么选择? Should the channel be recreated every time the WCF service method is being called? 是否应在每次调用WCF服务方法时重新创建通道?

[ 1. previous working state; [1.以前的工作状态; 2. newly attempted solution; 2.新尝试的解决方案; 3. fall-back option ] 3.后备选项]

  1. WCF Client -> ASP.NET -> Session cached factory -> Channel -> WCF Service WCF客户端-> ASP.NET->会话缓存的工厂->频道-> WCF服务
  2. WCF Client -> ASP.NET -> Cannot store factory! WCF客户端-> ASP.NET->无法存储工厂! -> Channel -> Azure role WCF Service ->频道-> Azure角色WCF服务
  3. WCF Client -> ASP.NET -> New channel each call -> Azure role WCF Service WCF客户端-> ASP.NET->每个调用新通道-> Azure角色WCF服务

Update : We've established, that it won't be possible to cache (share) the ChannelFactory. 更新 :我们已经确定,将无法缓存(共享)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. 因此,问题仍然存在,我如何共享因此现在不共享的凭据(UserNameCredentials),并且必须以某种方式在拆分实例之间进行分配。 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... 这继续作为一个新问题: 如何共享WCF客户端凭据...

If you want to cache the ChannelFactory, you are going to need to have one per session per azure role instance. 如果要缓存ChannelFactory,则每个天蓝色角色实例的每个会话将需要一个。 You are correct that CacheFactories should not be shared across sessions as they may be supporting different users. 您是正确的,不应在会话之间共享CacheFactories,因为它们可能支持不同的用户。

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. 正确地说,CacheFactory不可序列化,因此您将无法将其放入分布式缓存中。

Half the reason to cache it is to avoid the set-up time for the CacheFactory (may be many 10's of milliseconds). 缓存的一半原因是避免了CacheFactory的建立时间(可能是10毫秒的毫秒数)。 Serializing it into and out of the cache may be even longer than that as the CacheFactory is fairly large in size. 由于CacheFactory的大小相当大,因此将其序列化进出缓存的时间可能甚至更长。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM