c# - 天蓝色存储模拟器(表)返回 400 错误请求或 403 禁止

标签 c# visual-studio-2012 azure-storage

问题:访问 Azure 开发表存储时我缺少什么?

注意:我可以访问我的 azure CLOUD 存储(当然使用不同的代码),但我在尝试访问开发存储时失败了。

我正在使用:

  • Visual Studio 2012
  • .Net Framework 4.0 C# 库
  • NuGet Widows 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>

仅供引用:在搜索 MSDN、StackOverflow 等时,我找到了 3 种获取 CloudStorageAccount 对象以访问存储模拟器的方法。前两个给出了上面的错误。第 3 个给出 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);

更新

如回答中所述,我没有正确的模拟器版本。 上面的开发存储连接 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);

最佳答案

第三个不起作用,因为您没有设置模拟器端点,它发送到服务帐户 devstoreaccount1 而不是您的本地模拟器。尝试使用 TableEndpoint= http://127.0.0.1:10002/devstoreaccount1例如。蔚蓝 emulator docs如有必要,请提供更多详细信息。

如果您看到 README section on the Emulator您会看到最新的存储库版本需要最低模拟器版本 4.2。这也应该提供下载链接。你得到 400 Bad Request 因为你正在使用的库版本使用旧模拟器无法知道的服务版本。

关于c# - 天蓝色存储模拟器(表)返回 400 错误请求或 403 禁止,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33527132/

相关文章:

warnings - 包括<string>并且没有预编译的 header 时,“警告C4350:行为更改”

azure - 无法从程序集“Microsoft.WindowsAzure.Storage,版本 = 4.3.0.0”加载类型 'Microsoft.WindowsAzure.Storage.Blob.CloudAppendBlob'

Azure 存储 - 使用存储访问策略时限制 SAS 中的 IP

asp.net - 在 Windows Azure Blob 存储中托管 ASPNET 页面?

visual-studio-2012 - Visual Studio 2012 代码覆盖率

entity-framework - 从 VS 2012 发布到 Azure 网站时,我的 Entity Framework 种子数据未插入 SQL Azure

c# - EF6 Linq 查询。仅包括返回子表的第一个条目

c# - WebApi—— Controller 继承——方法的新版本

c# - 使 CRL 缓存无效

c# - 如何通过 C# 程序运行外部程序?