Reputation: 643
I have inherited a C++ app (of which Im no expert, Im a .NET guy) which sends messages to an azure queue in a JSON form. This works fine, its when I try and pick the message off the queue in my .NET console app that gives me the following message:
“The input is not a valid Base-64 string as it contains a non-base 64 character, more than two padding characters, or a non-white space character among the padding characters”.
The C++ code looks like this (notice the commented out dummy message which gives an example of what it looks like)
void send(utility::string_t msg) {
// Define the connection-string with your values.
const utility::string_t storage_connection_string(U("DefaultEndpointsProtocol=https;AccountName=bogus;AccountKey=YcG8FP9HdaB+r5jDTruTzZy8dXku+fLr4hvPcq+C6Uzhh7UOB6C7MemYluQMz28JlzwZIcn6Vw=="));
// Retrieve storage account from connection string.
azure::storage::cloud_storage_account storage_account = azure::storage::cloud_storage_account::parse(storage_connection_string);
// Create a queue client.
azure::storage::cloud_queue_client queue_client = storage_account.create_cloud_queue_client();
// Retrieve a reference to a queue.
azure::storage::cloud_queue queue = queue_client.get_queue_reference(U("beam-queue"));
// Create the queue if it doesn't already exist.
queue.create_if_not_exists();
// Create a message and add it to the queue.
//Dummy message
//azure::storage::cloud_queue_message message(U("[{\"url\":\"https://www.google.com.au\",\"app\":null,\"email\":\"[email protected]\",\"dbId\":\"323e3098-cc87-4b37-8eb5-85a6d6ddba1c\",\"seconds\":147.0490574,\"date\":\"2016-11-17T00:00:00+11:00\"}]"));
azure::storage::cloud_queue_message message(msg);
queue.add_message(message);
lastsendtime = GetTickCount();
}
I can even see the message in the storage explorer:
But it seems to be in the wrong format as when i pick the message off the queue:
CloudStorageAccount storageAccount = CloudStorageAccount.Parse(GetConnectionString());
CloudQueueClient queueClient = storageAccount.CreateCloudQueueClient();
CloudQueueClient clnt = storageAccount.CreateCloudQueueClient();
CloudQueue queue = clnt.GetQueueReference("bogus");
queue.EncodeMessage = true;
List<Service> userServices = null;
CloudQueueMessage retrievedMessage = queue.GetMessage();
List<CloudAppItem> items = JsonConvert.DeserializeObject<List<CloudAppItem>>(queue.GetMessage().AsString);
It fails in the last line. And its not because of the serializer. The queue.GetMessage().AsString returns the error.
UPDATE (Still not working)
I took out the encodedmessage statement, as I had previous tried to add it in to make it work. It still doesnt work. I also show the raw string, not accessible due to the fact it is private method on the class:
Upvotes: 1
Views: 756
Reputation: 27825
I took out the encodedmessage statement, as I had previous tried to add it in to make it work. It still doesnt work.
In your screenshot, we could find that you just remove queue.EncodeMessage = true;
, but the default value of CloudQueue.EncodeMessage property is true, please explicitly set CloudQueue.EncodeMessage to false.
CloudQueueClient clnt = storageAccount.CreateCloudQueueClient();
CloudQueue queue = clnt.GetQueueReference("bogus");
queue.EncodeMessage = false; //explicitly set CloudQueue.EncodeMessage to false
Upvotes: 2
Reputation: 136356
The reason you're getting this error is because you're instructing the SDK to decode the message from a base64 encoded string however the message contents is not base64 encoded (you're saving the message as plain text).
Please change the following line of code:
queue.EncodeMessage = true;
to
queue.EncodeMessage = false;
And that should take care of the problem. From CloudQueue.EncodeMessage
documentation:
Gets or sets a value indicating whether to apply base64 encoding when adding or retrieving messages.
Upvotes: 1