c# - c++ Azure存储队列发送错误类型的字符串

标签 c# c++ azure azure-storage

我继承了一个 C++ 应用程序(我不是专家,我是 .NET 人员),它以 JSON 形式将消息发送到 azure 队列。这工作正常,当我尝试从 .NET 控制台应用程序中的队列中选取消息时,它会向我提供以下消息:

“输入不是有效的 Base-64 字符串,因为它包含非 Base-64 字符、两个以上的填充字符或填充字符中的非空白字符”。

C++ 代码如下所示(请注意注释掉的虚拟消息,它给出了其外观的示例)

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\":\"<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="4329350329356d2a26" rel="noreferrer noopener nofollow">[email protected]</a>\",\"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();
}

我什至可以在存储资源管理器中看到该消息:

enter image description here

但当我从队列中选取消息时,它的格式似乎错误:

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);

最后一行失败了。这不是因为序列化器。 queue.GetMessage().AsString 返回错误。

enter image description here

更新(仍然不起作用)

我取出了编码消息语句,因为我之前曾尝试将其添加到其中以使其正常工作。它仍然不起作用。我还显示了原始字符串,由于它是类上的私有(private)方法,因此无法访问:

enter image description here

最佳答案

I took out the encodedmessage statement, as I had previous tried to add it in to make it work. It still doesnt work.

your screenshot ,我们可以发现你只是删除了queue.EncodeMessage = true;,但是默认值CloudQueue.EncodeMessage property为 true,请明确将 CloudQueue.EncodeMessage 设置为 false。

CloudQueueClient clnt = storageAccount.CreateCloudQueueClient();
CloudQueue queue = clnt.GetQueueReference("bogus");
queue.EncodeMessage = false;  //explicitly set CloudQueue.EncodeMessage to false

关于c# - c++ Azure存储队列发送错误类型的字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42082973/

相关文章:

c# - 已知地址时如何获取坐标?

C++:使用函数指针作为模板参数

c++ - 如何比较两个包含十进制值的字符串?

azure - 如何从 iOS 在 Azure 移动应用程序通知中心注册目标推送通知

c# - 如何使用反射和抽象对象动态加载类?

c# - 将流编码为 UTF-8 而不是 ASCII 后无法读取流中的整数

c# - 有谁知道 AsyncPageable 是什么?

c# - 用于在 azure 中上传 blob 的文件名约定

c# - 一维快速傅立叶变换

c++ - 英特尔 SGX 将整数从应用程序传递到 Enclave