2017-02-21 64 views
0

我能够使用SDK对队列进行C#库调用。但是,我无法对队列进行REST调用。如何将REST调用到Azure队列

我应该怎么做?任何代码示例将不胜感激。

+0

请告诉我们到目前为止您已经尝试了什么以及您遇到了哪些问题。我确信,如果你做了一个适当的搜索,你会发现很多C#代码示例,其中正在使用REST API而不是使用.Net SDK。 –

+0

@GauravMantri我试图做一些搜索,但我无法找到符合我的要求的人。我对azure很新。任何示例代码链接将不胜感激 – pankaj

+0

尽管有点旧,但看看这里:https: //azurestoragesamples.codeplex.com。这应该给你一个关于如何进行的想法。 –

回答

0

我能够做一个C#库调用使用SDK的队列。但是,我无法对队列进行剩余呼叫。我应该如何进行,任何代码示例将不胜感激。

首先,this link名单与信息工作REST操作将排队Azure存储提供,请检查链接以获取详细信息。其次,这里是一个示例请求create a queue under the given account,你可以像这样构建你的请求。

HttpWebRequest req = (HttpWebRequest)WebRequest.Create(string.Format(CultureInfo.InvariantCulture, 
"https://{0}.queue.core.windows.net/{1}", 
StorageAccount, queuename)); 

req.Method = "PUT"; 
req.Headers.Add("Authorization", AuthorizationHeader); 
req.Headers.Add("x-ms-date", mxdate); 
req.Headers.Add("x-ms-version", storageServiceVersion); 
req.ContentLength = 0; 

和请参阅下面的代码和Authentication for the Azure Storage Services构建签名串,用于生成AuthorizationHeader

string canonicalizedHeaders = string.Format(
    "x-ms-date:{0}\nx-ms-version:{1}", 
    mxdate, 
    storageServiceVersion); 

string canonicalizedResource = string.Format("/{0}/{1}", StorageAccount, queuename); 

string stringToSign = string.Format(
"{0}\n\n\n\n\n\n\n\n\n\n\n\n{1}\n{2}", 
requestMethod, 
canonicalizedHeaders, 
canonicalizedResource); 

请求看起来像这样。

0

有官方文档中的例子:

Request: 
POST https://myaccount.queue.core.windows.net/messages?visibilitytimeout=30&timeout=30 HTTP/1.1 

Headers: 
x-ms-version: 2011-08-18 
x-ms-date: Tue, 30 Aug 2011 01:03:21 GMT 
Authorization: SharedKey myaccount:sr8rIheJmCd6npMSx7DfAY3L//V3uWvSXOzUBCV9wnk= 
Content-Length: 100 

Body: 
<QueueMessage> 
<MessageText>PHNhbXBsZT5zYW1wbGUgbWVzc2FnZTwvc2FtcGxlPg==</MessageText> 
</QueueMessage> 

https://docs.microsoft.com/en-us/rest/api/storageservices/fileservices/put-message