問題:我缺少什麼來訪問Azure開發表存儲?azure存儲模擬器(表)返回400個錯誤請求或403個禁止
注意:我可以訪問我的天藍色CLOUD存儲(當然使用不同的代碼),但是我在嘗試訪問開發存儲時失敗。
我使用:
- 的Visual Studio 2012
- 框架4.0的C#庫
- 的NuGet寡婦Azure存儲V6.0 < ==修正 - 使用v6.1.0.0
- 適用於.net 2.6的Microsoft Azure SDK
Microsoft Azure存儲模擬器v4.0 < - 更改爲V4.2固定的問題
var cloudStorageAccount = CloudStorageAccount.DevelopmentStorageAccount; var tableClient = cloudStorageAccount.CreateCloudTableClient(); var table = tableClient.GetTableReference("MYTEMPTABLE"); var iscreated = table.CreateIfNotExists();
最後一條語句給出了這樣的例外
The remote server returned an error: (400) Bad Request. The value for one of the HTTP headers is not in the correct format. RequestId:f0b37575-30f4-45c1-bec3-2620c3c605e7 Time:2015-11-04T16:12:37.4719620Z
堆棧跟蹤
at Microsoft.WindowsAzure.Storage.Core.Executor.Executor.ExecuteSync[T](RESTCommand`1 cmd, IRetryPolicy policy, OperationContext operationContext) in c:\Program Files (x86)\Jenkins\workspace\release_dotnet_master\Lib\ClassLibraryCommon\Core\Executor\Executor.cs:line 816
at Microsoft.WindowsAzure.Storage.Table.TableOperation.Execute(CloudTableClient client, CloudTable table, TableRequestOptions requestOptions, OperationContext operationContext) in c:\Program Files (x86)\Jenkins\workspace\release_dotnet_master\Lib\ClassLibraryCommon\Table\TableOperation.cs:line 41
at Microsoft.WindowsAzure.Storage.Table.CloudTable.Exists(Boolean primaryOnly, TableRequestOptions requestOptions, OperationContext operationContext) in c:\Program Files (x86)\Jenkins\workspace\release_dotnet_master\Lib\ClassLibraryCommon\Table\CloudTable.cs:line 1605
at Microsoft.WindowsAzure.Storage.Table.CloudTable.CreateIfNotExists(TableRequestOptions requestOptions, OperationContext operationContext) in c:\Program Files (x86)\Jenkins\workspace\release_dotnet_master\Lib\ClassLibraryCommon\Table\CloudTable.cs:line 1024
at USPS.Cloud.Integration.AspProviders.UspsReturnsStorageBase.CreateStorageAccountFromConnectionString() in ... <my local code call stack>
FYI:在搜索MSDN,StackOverflow上,等,我找到了3種方法來獲取CloudStorageAccount對象來訪問存儲模擬器。前兩個給出了上面的錯誤。第三個給出了403錯誤。
CloudStorageAccount = CloudStorageAccount.DevelopmentStorageAccount;
CloudStorageAccount = CloudStorageAccount.Parse("UseDevelopmentStorage=true");
var devAccountName = "devstoreaccount1";
var devAccountKey = "Eby8vdM02xNOcqFlqUwJPLlmEtlCDXJ1OUzFT50uSRZ6IFsuFq2UVErCz4I6tq/K1SZFPTOtr/KBHBeksoGMGw==";
var devCredentials = new StorageCredentials(devAccountName, devAccountKey);
var cloudStorageAccount = new CloudStorageAccount(devCredentials, true);
UPDATE
如回答說,我沒有正確的模擬器版本。 開發存儲連接1 & 2上述工作。繼由@Emily Gerner答案的鏈接 - MSFT使我這個爲一個工作的選項3.
var devConnectionString = "DefaultEndpointsProtocol=http;AccountName=devstoreaccount1;AccountKey=Eby8vdM02xNOcqFlqUwJPLlmEtlCDXJ1OUzFT50uSRZ6IFsuFq2UVErCz4I6tq/K1SZFPTOtr/KBHBeksoGMGw==;BlobEndpoint=http://127.0.0.1:10000/devstoreaccount1;TableEndpoint=http://127.0.0.1:10002/devstoreaccount1;QueueEndpoint=http://127.0.0.1:10001/devstoreaccount1;";
CloudStorageAccount = CloudStorageAccount.Parse(devConnectionString);
確實,您必須運行通過Web Platform Installer最容易獲得的Microsoft Azure SDK 2.7.1。 – irhetoric
有趣的是,雖然這個答案是從2015年開始的,但是即使使用VS 2017,版本4.1仍然與Azure工具一起提供。我不得不通過從微軟頁面下載4.2來手動更新模擬器。 – zuckerthoben