Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I tried the following code and it worked fine for me. I created a queue, inserted a message did a "GET" message on that to get the pop receipt and then deleted the message. Only thing I modified in your code is the canonicalizedResource string based on my answer above:</p> <pre><code>using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Net; using System.Web; using System.IO; using System.Security.Cryptography; using System.Globalization; namespace ConsoleApplication15 { class Program { static void Main(string[] args) { string messageId = "&lt;message id e.g. ba9bdbe6-cd10-465d-ab32-90756ea0471d&gt;"; string queueName = "&lt;queue name e.g. abc&gt;"; string accountName = "&lt;your account name&gt;"; string accountKey = "&lt;you account key base64 encoded string&gt;"; string endpoint = "http://accountname.queue.core.windows.net/"; string popreceipt = "&lt;pop receipt e.g. AgAAAAEAAAAAAAAACuMLtGTIzQE=&gt;"; var result = DeleteMessage(queueName, accountName, Convert.FromBase64String(accountKey), endpoint, popreceipt, messageId); } public static string DeleteMessage(String queueName, string account, byte[] key, string endpoint, string popreceipt, string messageid) { string requestMethod = "DELETE"; String urlPath = String.Format("{0}/messages/{1}?popreceipt={2}", queueName, Uri.EscapeDataString(messageid), Uri.EscapeDataString(popreceipt)); String storageServiceVersion = "2009-09-19"; String dateInRfc1123Format = DateTime.UtcNow.ToString("R", CultureInfo.InvariantCulture); String canonicalizedHeaders = String.Format( "x-ms-date:{0}\nx-ms-version:{1}", dateInRfc1123Format, storageServiceVersion); String canonicalizedResource = string.Format("/{0}/{1}/messages/{2}\npopreceipt:{3}", account, queueName, messageid, popreceipt); String stringToSign = String.Format( "{0}\n\n\n\n\n\n\n\n\n\n\n\n{1}\n{2}", requestMethod, canonicalizedHeaders, canonicalizedResource); String authorizationHeader = CreateAuthorizationHeader(stringToSign, account, key); Uri uri = new Uri(endpoint + urlPath); HttpWebRequest request = (HttpWebRequest)WebRequest.Create(uri); request.Method = requestMethod; request.Headers.Add("x-ms-date", dateInRfc1123Format); request.Headers.Add("x-ms-version", storageServiceVersion); request.Headers.Add("Authorization", authorizationHeader); using (HttpWebResponse response = (HttpWebResponse)request.GetResponse()) { Stream dataStream = response.GetResponseStream(); return response.StatusCode.ToString(); } } private static String CreateAuthorizationHeader(String canonicalizedString, string account, byte[] key) { String signature = string.Empty; using (HMACSHA256 hmacSha256 = new HMACSHA256(key)) { Byte[] dataToHmac = System.Text.Encoding.UTF8.GetBytes(canonicalizedString); signature = Convert.ToBase64String(hmacSha256.ComputeHash(dataToHmac)); } String authorizationHeader = String.Format( CultureInfo.InvariantCulture, "{0} {1}:{2}", "SharedKey", account, signature); return authorizationHeader; } } } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload