0

我正在尝试基于http://msdn.microsoft.com/en-us/library/windowsazure/gg618003上的代码的概念证明。如果我使用 app.config 设置,则可以访问此缓存。当我将应用程序切换为使用编程配置时,我一直收到此错误。我已经尝试过以编程方式配置 Azure 缓存无法验证,并且许多其他解决方案都无济于事。

这是我的代码片段。

{代码}

        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();

{代码}

4

1 回答 1

0

尝试在创建时传递所有参数而不是在创建后传递?

    var configFactory = new DataCacheFactoryConfiguration
                            {
                                Servers =
                                    new List<DataCacheServerEndpoint>
                                        {new DataCacheServerEndpoint(cacheServer, cachePort)},
                                SecurityProperties =
                                    new DataCacheSecurity(Encryption.CreateSecureString(cacheAuthorization),
                                                          true)
                            };
于 2012-09-11T21:01:53.913 回答