当实例化HttpNotificationChannel时,Channeluri为NULL [英] Channeluri is NULL when instanciated the HttpNotificationChannel

查看:107
本文介绍了当实例化HttpNotificationChannel时,Channeluri为NULL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好

我现在面临一个问题,试图创建一个新的HttpNotificationChannel实例。在创建它时,ChannelUri属性为NULL。

I am facing a problem at the moment to try to create a new instance of the HttpNotificationChannel. When creating it, the ChannelUri property is NULL.

这是代码:

const string channelName = "MyChannel";
        HttpNotificationChannel notificationChannel;

        private void btnChannel_Click(object sender, RoutedEventArgs e)
        {
            notificationChannel = HttpNotificationChannel.Find(channelName);
            if (notificationChannel == null)
            {
                notificationChannel = new HttpNotificationChannel(channelName);
                notificationChannel.ChannelUriUpdated += notificationChannel_ChannelUriUpdated;
                notificationChannel.ErrorOccurred += notificationChannel_ErrorOccurred;
            }

            notificationChannel.Open();
        }

        void notificationChannel_ErrorOccurred(object sender, NotificationChannelErrorEventArgs e)
        {
            Dispatcher.BeginInvoke(() => this.txtChannel.Text = "Error: " + e.Message);
        }

        void notificationChannel_ChannelUriUpdated(object sender, NotificationChannelUriEventArgs e)
        {
            Dispatcher.BeginInvoke(() => this.txtChannel.Text = e.ChannelUri.ToString());
        }

我想,'因为ChannelUri设置为null,ErrorOcurred和ChannUriUpdated不会被触发。

I guess, 'cause the ChannelUri is set to null, the ErrorOcurred and ChannUriUpdated aren't getting fired.

仅供参考,我正在我的设备中直接测试它(诺基亚Lumia 920)

FYI, I'm testing it directly in my device (Nokia Lumia 920)

如果有人知道发生这种情况的原因,任何线索都会非常有用。

If anyone know the reason why this happening, any clue would be very helpfull.

提前致谢;)

推荐答案

当您创建HttpNotificationChannel的实例时,ChannelUri将为null。

When you create an instance of HttpNotificationChannel the ChannelUri will be null.

当您致电notificationChannel.Open()时,设备将尝试联系通知服务。 

When you call notificationChannel.Open() the device will attempt to contact the notification service. 

一旦设备与通知服务器成功通信,它将触发ChannelUriUpdated,此时ChannelUri将有一个值。

Once the device completes successful communication with the notification server it will fire ChannelUriUpdated, at which point ChannelUri will have a value.

如果没有可用的网络连接或通知服务器响应错误,则会触发ErrorOccurred事件,并且ChannelUri将保持为空。

If no network connection is available or if the notification server responds with error then ErrorOccurred event will fire and ChannelUri will remain null.

!!如果网络连接可用但设备无法从通知服务器接收任何响应,则两个事件都不会触发。 

!! If a network connection is available but the device is unable to receive any response from the notification server then neither event will fire. 


这篇关于当实例化HttpNotificationChannel时,Channeluri为NULL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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