1

我正在使用 Windows Phone 应用程序,但我不知道为什么,但我没有获得 HttpNotification 通道的通道 URI。

我收到“System.NullReferenceException”。我的代码在前一天工作,但相同的代码今天不工作。

我的 C# 代码是:

    HttpNotificationChannel pushChannel;          
    string channelName = "ToastSampleChannel";

    // 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, "www.contoso.com");

        // 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.
        System.Diagnostics.Debug.WriteLine(pushChannel.ChannelUri.ToString());
        MessageBox.Show(String.Format("Channel Uri is {0}",
            pushChannel.ChannelUri.ToString()));

    }

我得到了这种类型的异常在此处输入图像描述

我不知道真正的问题是什么?这是服务器问题还是其他?

4

1 回答 1

0

根据我的经验,在退出应用程序之前检查您的通知通道绑定状态。如果它没有同时绑定到 tile 和 toast,Microsoft Push Notification Service 将使其订阅无效,并且您将在下次打开应用程序时得到一个空的 channelUrl。

于 2013-07-10T11:17:01.163 回答