pankaj
pankaj

Reputation: 1060

How to make a REST call to an Azure Queue

I am able to make a C# library call to a queue using the SDK. However I am unable to make a REST call to the queue.

How shall I proceed? Any code sample will be appreciated.

Upvotes: 0

Views: 4889

Answers (2)

Fei Han
Fei Han

Reputation: 27825

I am able to make a c# library call to a queue using SDK. However i am unable to make a Rest Call to the queue. How shall i proceed and Any code sample will be appreciated.

Firstly, this link lists the REST operations for working with message queues that Azure Storage provides, please check the link to get detailed informations.

Secondly, here is a sample request to create a queue under the given account, you could construct your request like this.

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;

and please refer to the following code and Authentication for the Azure Storage Services to construct the signature string for generating 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);

the request looks like this.

enter image description here

Upvotes: 1

Thiago Custodio
Thiago Custodio

Reputation: 18387

There are examples in the official documentation:

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://learn.microsoft.com/en-us/rest/api/storageservices/fileservices/put-message

Upvotes: 0

Related Questions