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

私の経験から、アプリを終了する前に、通知チャネルのバインド状態を確認してください。タイルとトーストの両方にバインドされていない場合、Microsoft プッシュ通知サービスはそのサブスクリプションを無効にし、次にアプリを開いたときに null channelUrl を取得します。

于 2013-07-10T11:17:01.163 に答える