0

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.

Andrew Bainbridge
  • 4,651
  • 3
  • 35
  • 50
pankaj
  • 1,030
  • 5
  • 19
  • 41
  • Please tell us what have you tried so far and what are the issues you're running into. I'm sure that if you do a proper search you will find lots of code samples in C# where REST API is being consumed instead of using .Net SDK. – Gaurav Mantri Feb 21 '17 at 07:52
  • @GauravMantri I tried to do some search, but I am not able to find the ones fitting my requirement.I am very new to azure.Any sample code link will be appreciated – pankaj Feb 21 '17 at 09:11
  • Though a bit old but take a look here: https://azurestoragesamples.codeplex.com. This should give you an idea about how to proceed. – Gaurav Mantri Feb 21 '17 at 09:17
  • we have shared you some samples, are you able to operate Azure queue via Rest API now? – Fei Han Mar 01 '17 at 06:06

2 Answers2

1

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

Fei Han
  • 26,415
  • 1
  • 30
  • 41
0

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

Thiago Custodio
  • 17,332
  • 6
  • 45
  • 90