【发布时间】:2013-10-04 09:32:23
【问题描述】:
尝试在本地创建 Azure 缓存实例时出现 InvalidOperationException(异常和代码如下所示)。该代码正在从控制台应用程序运行。当我在 azure 模拟器中以工作角色运行它时,它工作正常。
是否可以在不运行模拟器的情况下使用 Azure 缓存?
{System.Reflection.TargetInvocationException: 出现异常 由调用的目标抛出。 ---> System.InvalidOperationException:角色发现数据不可用
在 Microsoft.WindowsAzure.ServiceRuntime.RoleEnvironment.get_Roles()
配置
<dataCacheClients>
<dataCacheClient name="mycache.cache.windows.net">
<autoDiscover
isEnabled="true"
identifier="mycache.cache.windows.net" />
<securityProperties mode="Message" sslEnabled="false">
<messageSecurity authorizationInfo="[mytoken]=" />
</securityProperties>
</dataCacheClient>
</dataCacheClients>
代码:
bool autoDiscover = true;
string identifier = "foo";
var cacheFactoryConfiguration = new DataCacheFactoryConfiguration
{
AutoDiscoverProperty = new DataCacheAutoDiscoverProperty(autoDiscover, identifier),
TransportProperties = new DataCacheTransportProperties { MaxBufferSize = int.MaxValue },
IsCompressionEnabled = true,
MaxConnectionsToServer = 3
};
var dataCacheFactory = new DataCacheFactory(cacheFactoryConfiguration);
【问题讨论】:
-
您使用的是哪个 Azure Cache 选项(服务、角色内 [专用]、角色内 [共同定位] 或共享)?
标签: c# azure azure-caching