如何从Windows Phone发送队列消息? [英] How to send queue message from Windows Phone?

查看:97
本文介绍了如何从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
                   }));

这篇关于如何从Windows Phone发送队列消息?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆