簡體   English   中英

本地使用Azure緩存時出現InvalidOperationException

[英]InvalidOperationException when using azure cache locally

嘗試在本地創建一個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 client configured by settings in application configuration file.
DataCacheFactoryConfiguration config = new DataCacheFactoryConfiguration("mycache.cache.windows.net");
DataCacheFactory cacheFactory = new DataCacheFactory(config);
DataCache defaultCache = cacheFactory.GetDefaultCache();    

// Put and retrieve a test object from the default cache.
defaultCache.Put("testkey", "testobject");
string strObject = (string)defaultCache.Get("testkey");

另請注意 -我不會在Azure共享緩存上進行任何開發-該服務將於2014年停用-請參見http://www.windowsazure.com/zh-cn/pricing/details/cache/

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM