我正在使用适用于Windows Phone的Windows Azure工具包,但我很难将队列消息发送到云服务。这是我的代码:
public void SendQueueMessage(string queueReference, params string[] message)
{
CloudQueue cloudQueue = new CloudQueue();
CloudQueueClient queueClient = new CloudQueueClient(queueUri, credentials);
queueClient.GetQueueReference(queueReference);
StringBuilder sb = new StringBuilder();
foreach (var messagePart in message)
{
sb.Append(messagePart);
sb.Append(":");
}
sb.Remove(sb.Length - 2, 1);
CloudQueueMessage queueMessage = new CloudQueueMessage { AsBytes = Encoding.UTF8.GetBytes(sb.ToString()) };
cloudQueue.AddMessage(queueMessage, r => this.dispatcher.BeginInvoke(() =>
{
if(r.Exception != null)
{
//handle exception
}
}));
}
我总是在AddMessage方法中得到null异常。有什么想法吗?
答案 0 :(得分:1)
我怀疑你现在可能已经发现了如何做到这一点,但经过深思熟虑后,我发现如何通过这一集cloudcove r从Windows Phone添加队列到存储。你应该在13:44分左右看一下。
http://www.joshholmes.com/blog/2012/01/18/using-windows-azure-storage-from-the-windows-phone/
希望这会帮助你
编辑:复制了视频中的代码后,它应该如下所示:
var queueClient = CloudStorageContext.Current.Resolver.CreateCloudQueueClient();
var queue = queueClient.GetQueueReference("imagestodo");
queue.Create(r => queue.AddMessage(
new CloudQueueMessage
{
AsBytes = Encoding.UTF8.GetBytes(imageID),
Id = imageID
},
c =>
{
//logic here
}));