2

我从 MSDN 下载了一个示例,用于向 Windows Phone 8 发送云通知。但我总是将通道 URI 设为 null ?我在模拟器 8 上运行它。

有什么想法吗 ??

public MainPage()
    {
        /// Holds the push channel that is created or found.
        HttpNotificationChannel pushChannel;

        // The name of our push channel.
        string channelName = "ToastSampleChannel";

        InitializeComponent();

        // Try to find the push channel.
        pushChannel = HttpNotificationChannel.Find(channelName);

        // If the channel was not found, then create a new connection to the push service.
        if (pushChannel == null)
        {
            pushChannel = new HttpNotificationChannel(channelName);

            // Register for all the events before attempting to open the channel.
            pushChannel.ChannelUriUpdated += new EventHandler<NotificationChannelUriEventArgs>(PushChannel_ChannelUriUpdated);
            pushChannel.ErrorOccurred += new EventHandler<NotificationChannelErrorEventArgs>(PushChannel_ErrorOccurred);

            // Register for this notification only if you need to receive the notifications while your application is running.
            pushChannel.ShellToastNotificationReceived += new EventHandler<NotificationEventArgs>(PushChannel_ShellToastNotificationReceived);

            pushChannel.Open();

            // Bind this new channel for toast events.
            pushChannel.BindToShellToast();

        }
        else
        {
            // The channel was already open, so just register for all the events.
            pushChannel.ChannelUriUpdated += new EventHandler<NotificationChannelUriEventArgs>(PushChannel_ChannelUriUpdated);
            pushChannel.ErrorOccurred += new EventHandler<NotificationChannelErrorEventArgs>(PushChannel_ErrorOccurred);

            // Register for this notification only if you need to receive the notifications while your application is running.
            pushChannel.ShellToastNotificationReceived += new EventHandler<NotificationEventArgs>(PushChannel_ShellToastNotificationReceived);

            // Display the URI for testing purposes. Normally, the URI would be passed back to your web service at this point.enter code here
            System.Diagnostics.Debug.WriteLine(pushChannel.ChannelUri.ToString());
            MessageBox.Show(String.Format("Channel Uri is {0}",
                pushChannel.ChannelUri.ToString()));

        }
    }

在上面的代码中,我总是将频道 Uri 设为“null”

4

2 回答 2

0

由于您使用模拟器,它将始终为空,请尝试本地机器。

于 2013-07-10T17:51:39.810 回答
0

所以问题出在我的网络环境上。当我在非域电脑上尝试时,它工作正常。感谢评论和时间

于 2013-07-16T20:26:46.897 回答