2015-11-04 55 views
3

问题:我缺少什么来访问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); 

回答

5

第三,你不是要设置模拟器端点不工作,它发送到服务账户devstoreaccount1而不是你的本地模拟器。例如,尝试使用TableEndpoint = http://127.0.0.1:10002/devstoreaccount1。如有必要,Azure emulator docs有更多细节。

如果您看到README section on the Emulator,您会看到最新的存储库版本需要最低仿真器版本4.2。这也应该提供一个下载链接。由于您使用的库版本使用旧版仿真器无法知晓的服务版本,因此您会收到400个错误请求。

+0

确实,您必须运行通过Web Platform Installer最容易获得的Microsoft Azure SDK 2.7.1。 – irhetoric

+0

有趣的是,虽然这个答案是从2015年开始的,但是即使使用VS 2017,版本4.1仍然与Azure工具一起提供。我不得不通过从微软页面下载4.2来手动更新模拟器。 – zuckerthoben

0

看起来AzureStorage NugetPackage> 6.0.0适用于Azure SDK 2.8(存储模拟器4。8)

0

我也得到了400错误。在我的情况下,我无法启动Azure存储模拟器。原因是其他进程正在监听该端口。所以我去了并更改AzureStorageEmulator.exe中的端口号。你可以找到这个配置文件@ C:\ Program Files(x86)\ Microsoft SDKs \ Azure \ Storage Emulator。或者你安装了模拟器。之后,模拟器启动。但这400人仍然没有消失。所以我在配置文件中使用了这个设置。 “UseDevelopmentStorage = true; DevelopmentStorageProxyUri = http://ipv4.fiddler” [Azure October 2012 SDK broke UseDevelopmentStorage=true。看着提琴手,我意识到请求正在被引导到端口号10000.我发现没有办法改变它。所以我杀了那个使用那个端口的进程。将我的配置文件重置为原始状态。现在,blob,队列和表正在使用原始端口号。 Azure存储模拟器已重新启动。现在神奇的400错误消失了。

相关问题