Bra*_*yce 3 c# azure-storage visual-studio-2012
Question: What am I missing to access azure development table storage?
Note: I can access my azure CLOUD storage (using different code of course), but I am failing when trying to access the development storage.
I'm using:
Microsoft Azure Storage Emulator v4.0 <- changing to v4.2 fixed issue
var cloudStorageAccount = CloudStorageAccount.DevelopmentStorageAccount;
var tableClient = cloudStorageAccount.CreateCloudTableClient();
var table = tableClient.GetTableReference("MYTEMPTABLE");
var iscreated = table.CreateIfNotExists();
Run Code Online (Sandbox Code Playgroud)
The last statement gives this exception
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
Run Code Online (Sandbox Code Playgroud)StackTrace
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>
Run Code Online (Sandbox Code Playgroud)
FYI: In searching MSDN, StackOverflow, etc, I've found 3 ways to get a CloudStorageAccount object to access the storage emulator. The first 2 give the error above. The 3rd gives a 403 error.
CloudStorageAccount = CloudStorageAccount.DevelopmentStorageAccount;
Run Code Online (Sandbox Code Playgroud)
CloudStorageAccount = CloudStorageAccount.Parse("UseDevelopmentStorage=true");
Run Code Online (Sandbox Code Playgroud)
var devAccountName = "devstoreaccount1";
var devAccountKey = "Eby8vdM02xNOcqFlqUwJPLlmEtlCDXJ1OUzFT50uSRZ6IFsuFq2UVErCz4I6tq/K1SZFPTOtr/KBHBeksoGMGw==";
var devCredentials = new StorageCredentials(devAccountName, devAccountKey);
var cloudStorageAccount = new CloudStorageAccount(devCredentials, true);
Run Code Online (Sandbox Code Playgroud)
UPDATE
As stated in the answer, I did not have the correct emulator version. Dev storage connections 1 & 2 above work. Following the link in the answer by @Emily Gerner - MSFT led me to this for a working option 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);
Run Code Online (Sandbox Code Playgroud)
第三个不起作用,因为您没有设置模拟器端点,而是发送到服务帐户 devstoreaccount1 而不是您的本地模拟器。例如,尝试使用 TableEndpoint= http://127.0.0.1:10002/devstoreaccount1。如果需要,Azure模拟器文档有更多详细信息。
如果您在模拟器上看到README 部分,您将看到最新的存储库版本需要最小模拟器版本 4.2。这还应提供下载链接。您会收到 400 Bad Request,因为您使用的库版本使用了旧模拟器无法了解的服务版本。
| 归档时间: |
|
| 查看次数: |
4307 次 |
| 最近记录: |