如何从Windows Phone发送队列消息?
我正在使用Windows Phone的Windows Azure工具包,但是我很难将队列消息发送到云服务。这是我的代码:
I'm using the Windows Azure toolkit for Windows Phone, but I have difficulities to send a queue message to the cloud service. Here is my code:
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异常。有什么想法吗?
I'm always getting null exception at AddMessage method.Any ideas?
我怀疑您现在可能已经找到了解决方法,但是经过一番寻找之后,我发现了如何从Windows Phone通过cloudcove r。您应该在13:44分钟左右看。
I suspect you may have found out how to do this by now but after much looking I found how to add a queue to storage from Windows Phone via this episode of cloudcove r. You should be looking at around the 13:44 minute mark.
http://www.joshholmes.com/blog/2012/01/18/using-windows-azure-storage-从窗口电话/
希望,这将对您有所帮助
Hopefully, this will help you out
编辑:复制了视频中的代码后,它应该看起来像这样:
Having copied the code from the video it should look something like this:
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
}));