简体   繁体   English

如何使用.Net Standard查询Azure表存储

[英]How to Query Azure Table storage using .Net Standard

I have a .Net Standard client application running on UWP. 我有一个在UWP上运行的.Net Standard客户端应用程序。

My client application contacts the server that generates a sas key like so: 我的客户端应用程序与生成sas密钥的服务器联系,如下所示:

var myPrivateStorageAccount = CloudStorageAccount.Parse(mystorageAccountKey);
var myPrivateTableClient = myPrivateStorageAccount.CreateCloudTableClient();
SharedAccessTablePolicy pol = new SharedAccessTablePolicy()
{
    SharedAccessExpiryTime = DateTime.UtcNow.AddMinutes(59),
    Permissions = SharedAccessTablePermissions.Query | SharedAccessTablePermissions.Add
};
CloudTable myPrivateTable = myPrivateTableClient.GetTableReference(tableName);
String sas = myPrivateTable.GetSharedAccessSignature(pol);
return sas;

My client application then runs the following: 然后,我的客户端应用程序运行以下命令:

StorageCredentials creds = new StorageCredentials(sas);

this.tableClient = new CloudTableClient(tableServiceURI, creds);
this.table = tableClient.GetTableReference(tableName);
TableQuery<DynamicTableEntity> projectionQuery = new TableQuery<DynamicTableEntity>().Select(new string[] { "DocumentName" }).Where(TableQuery.GenerateFilterCondition("PartitionKey", QueryComparisons.Equal, cc));
 var res = await table.ExecuteQuerySegmentedAsync<DynamicTableEntity>(projectionQuery, null);

and gets the following error: 并得到以下错误:

Server failed to authenticate the request. 服务器无法验证请求。 Make sure the value of Authorization header is formed correctly including the signature. 确保包括签名在内的Authorization标头的值正确形成。 sr is mandatory. sr是强制性的。 Cannot be empty 不能为空

but as this is tablestorage I dont think sr is required 但是因为这是tabletorage, 所以我认为不需要sr

and my SAS key looks fine to me: 我的SAS密钥对我来说看起来不错:

?sv=2018-03-28&tn=MyTable&sig=RandomSig151235341543&st=2019-01-17T12%3A00%3A28Z&se=2019-01-17T12%3A59%3A28Z&sp=ra ?SV = 2018年3月28日与TN = MyTable的&SIG = RandomSig151235341543&ST = 2019-01-17T12%3A00%3A28Z&SE = 2019-01-17T12%3A59%3A28Z&SP = RA

so whats the problem here? 那么这是什么问题呢?

Ok so this is kind of stupid but I will post anyway. 好的,这有点愚蠢,但是我还是会发布。

I was sending the request to: 我正在将请求发送到:

https://myaccount.blob.core.windows.net/ https://myaccount.blob.core.windows.net/

and should have been sending the request to: 并且应该已经将请求发送至:

https://myaccount.table.core.windows.net/ https://myaccount.table.core.windows.net/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM