Windows Azure 本機存放區 SetConfigurationSettingPublisher needs to be called before FromConfigurationSetti

來源:互聯網
上載者:User

今天開放 Windows Azure 儲存服務的時候碰到一個問題:

執行下面的初始化儲存代碼

// read account configuration settingsvar storageAccount = CloudStorageAccount.FromConfigurationSetting("DataConnectionString");

拋出異常

網上找了一些資料 沒有收穫 於是回去看Windows azure 白皮書中的樣本描述,發現少了一段很重要的代碼

這是My Code

namespace WCFServiceWebRole{    public class WebRole : RoleEntryPoint    {        public override bool OnStart()        {            DiagnosticMonitor.Start("DiagnosticsConnectionString");            // 有關處理配置更改的資訊,            // 請參見 http://go.microsoft.com/fwlink/?LinkId=166357 上的 MSDN 主題。            RoleEnvironment.Changing += RoleEnvironmentChanging;            return base.OnStart();        }        private void RoleEnvironmentChanging(object sender, RoleEnvironmentChangingEventArgs e)        {            // 如果配置設定發生更改,            if (e.Changes.Any(change => change is RoleEnvironmentConfigurationSettingChange))            {                // 請將 e.Cancel 設定為 true 以重新啟動此角色執行個體                e.Cancel = true;            }        }    }}

 

 

修改之後的代碼

namespace WCFServiceWebRole{    public class WebRole : RoleEntryPoint    {        public override bool OnStart()        {            DiagnosticMonitor.Start("DiagnosticsConnectionString");            // 有關處理配置更改的資訊,            // 請參見 http://go.microsoft.com/fwlink/?LinkId=166357 上的 MSDN 主題。            RoleEnvironment.Changing += RoleEnvironmentChanging;            // 當使用設定檔中ConfigurationSettings時必須調用CloudStorageAccount.SetConfigurationSettingPublisher            // 來說明當設定檔在發布後被更改時將採取何種操作             Microsoft.WindowsAzure.CloudStorageAccount.SetConfigurationSettingPublisher((configName, configSetter) =>            {                configSetter(Microsoft.WindowsAzure.ServiceRuntime.RoleEnvironment.GetConfigurationSettingValue(configName));                 RoleEnvironment.Changed += (sender, arg) =>                {                    if (arg.Changes.OfType<RoleEnvironmentConfigurationSettingChange>()                        .Any((change) => (change.ConfigurationSettingName == configName)))                    {                        if (!configSetter(RoleEnvironment.GetConfigurationSettingValue(configName)))                        {                            RoleEnvironment.RequestRecycle();                        }                    }                };            return base.OnStart();        }        private void RoleEnvironmentChanging(object sender, RoleEnvironmentChangingEventArgs e)        {            // 如果配置設定發生更改,            if (e.Changes.Any(change => change is RoleEnvironmentConfigurationSettingChange))            {                // 請將 e.Cancel 設定為 true 以重新啟動此角色執行個體                e.Cancel = true;            }        }    }}

原因就是少了這個方法SetConfigurationSettingPublisher,

vs2010建項目的時候該方法不會自動產生,導致後面雲端儲存賬戶失敗。

pos:目前雲端運算在windows azure國內剛起步,這方面的教程特別少 僅限於一般的入門級教程 碰到疑難問題最好google國外的技術資料

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.