12

I don't have the possibility to encode my request to base64, and according to the documentation I shouldn't have to, but I can't figure it out.

If I Base64 encode it's working fine:

<QueueMessage>
<MessageText>PHNhbXBsZT5zYW1wbGUgbWVzc2FnZTwvc2FtcGxlPg==</MessageText>
</QueueMessage>

Which adds the decoded message to the queue:

<sample>sample message</sample>

According to the documentation (https://msdn.microsoft.com/sv-se/library/azure/dd179346.aspx)

A message must be in a format that can be included in an XML request with UTF-8 encoding. To include markup in the message, the contents of the message must either be XML-escaped or Base64-encode. Any XML markup in the message that is not escaped or encoded will be removed before the message is added to the queue.

Trying to add (instead of PHNhbXBsZT5zYW1wbGUgbWVzc2FnZTwvc2FtcGxlPg==):

&lt;sample&gt;sample message&lt;/sample&gt;

Succeeds but when trying to view the message in the queue it only responds with:

The input is not a valid Base-64 string as it contains a non-base 64 character, more than two padding characters, or an illegal character among the padding characters.

Does somebody know how send a proper raw xml-escaped request message to the storage queue?

Full request (without keys and names):

POST https://xxxxxxx.queue.core.windows.net/testqueue/messages?sv=2015-04-05&ss=q&srt=sco&sp=a&se=2026-11-11T20:24:03Z&st=2016-11-11T12:24:03Z&spr=https&sig=xxxxxxxxxxxxxxxxx%3D HTTP/1.1
User-Agent: Fiddler
Host: XXXXX.queue.core.windows.net
Content-Type: text/plain
Content-Length: 64

<QueueMessage>
<MessageText>&lt;sample&gt;sample message&lt;/sample&gt;</MessageText>
</QueueMessage>
Liam
  • 27,717
  • 28
  • 128
  • 190
thllbrg
  • 2,017
  • 17
  • 21
  • How are you viewing the messages? Are you using some tool for that? – Gaurav Mantri Nov 11 '16 at 16:05
  • I'm viewing them from Visual Studios (2015) Cloud Explorer – thllbrg Nov 11 '16 at 16:12
  • This could be an issue with Cloud Explorer. Can you try viewing the message in some other tool? – Gaurav Mantri Nov 11 '16 at 16:15
  • I'm able to view it using Microsoft Azure Cloud Explorer, but it looks like it has tried to decode a base64 encoded string, "�������^��,j������" in my case i would like it to decode a xml-escaped string. – thllbrg Nov 11 '16 at 16:25
  • 1
    Please try Cerebrata Azure Management Studio or Cloud Portam (Disclosure: I am part of the team who has built these tools). – Gaurav Mantri Nov 11 '16 at 16:29
  • I will give it a go, but to me the problem seems to be with the posting, not reading it from the queue. – thllbrg Nov 11 '16 at 16:33
  • I don't think so. I would recommend tracing the response in a tool like Fiddler. The tools are assuming that the message content is stored as base64 encoded and tries to decode it always and fails because it is not saved as base64 encoded. – Gaurav Mantri Nov 11 '16 at 16:36
  • Right you are! Shows up perfectly in Cerebrata Azure Management Studio, thanks! – thllbrg Nov 11 '16 at 16:46

2 Answers2

9

I was getting format errors calling the AsString property because the message returned from the storage queue was, by default, base64 encoded.

The CloudQueue object has an EncodeMessage property that was set to true. Switched it to false and everything worked. Here's my code:

 CloudQueueClient queueClient = storageAccount.CreateCloudQueueClient();
 CloudQueue queue = queueClient.GetQueueReference(ClientQueueName);
 queue.EncodeMessage = false;
 CloudQueueMessage retrievedMessage = queue.GetMessage();

ClientQueueName being a string holding the name of my queue on Azure. I'm thinking that the property needs to be set to false in your case before sending as well.

John Donnelly
  • 875
  • 1
  • 10
  • 29
5

John Donnelly answer. is now out of date. CloudQueue is now considered legacy and you should be using QueueClient instead. QueueClient does not have an EncodeMessage property but you can specify the MessageEncoding when injecting the service:

builder.Services.AddAzureClients(builder => {
      builder.AddQueueServiceClient(<connection string>)
         .ConfigureOptions(o => o.MessageEncoding = QueueMessageEncoding.None);
}
Liam
  • 27,717
  • 28
  • 128
  • 190