我正在尝试基于http://msdn.microsoft.com/en-us/library/windowsazure/gg618003的代码的概念证明。如果我使用app.config设置,则可以访问此缓存。当我将应用程序切换为使用程序配置时,我始终遇到此错误。我已经尝试了Azure cache programatically configuration fail to verify和许多其他解决方案无济于事。
这是我的代码段。
{代码}
String acsKey = "AcsKey removed intentionaly";
DataCacheFactoryConfiguration cacheFactoryConfiguration;
DataCacheSecurity dataCacheSecurity;
DataCacheServerEndpoint[] serverEndpoints = new DataCacheServerEndpoint[1];
SecureString secureAcsKey = new SecureString();
serverEndpoints[0] = new DataCacheServerEndpoint("EndPont removed intentionaly", 22243);
//
// Create SecureString from string
//
foreach (char keyChar in acsKey)
{
secureAcsKey.AppendChar(keyChar);
}
secureAcsKey.MakeReadOnly();
dataCacheSecurity = new DataCacheSecurity(secureAcsKey);
//
// Initialize Factory Configuration
//
cacheFactoryConfiguration = new DataCacheFactoryConfiguration(); // This line throws exception. Note that the key is yet to be assigned to SecurityProperties as per documentation.
cacheFactoryConfiguration.Servers = serverEndpoints;
cacheFactoryConfiguration.SecurityProperties = dataCacheSecurity;
_cacheFactory = new DataCacheFactory(cacheFactoryConfiguration);
_cache = _cacheFactory.GetDefaultCache();
{代码}
答案 0 :(得分:0)
尝试在创建时传递所有参数,而不是在创建后传递?
var configFactory = new DataCacheFactoryConfiguration
{
Servers =
new List<DataCacheServerEndpoint>
{new DataCacheServerEndpoint(cacheServer, cachePort)},
SecurityProperties =
new DataCacheSecurity(Encryption.CreateSecureString(cacheAuthorization),
true)
};