0

I'm developing a Windows Phone 8 app that uses Raw Notification. For this, I'm following the sample "How to send and receive raw notifications for Windows Phone 8".

I coded exactly as the sample:

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

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

            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);
                pushChannel.HttpNotificationReceived += new EventHandler<HttpNotificationEventArgs>(PushChannel_HttpNotificationReceived);

                pushChannel.Open();

            }
            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);
                pushChannel.HttpNotificationReceived += new EventHandler<HttpNotificationEventArgs>(PushChannel_HttpNotificationReceived);

                // 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()));

            }
        }

After I ran the code in a device, I saw that the app is generating a different URI each time I launch it.

I realized that HttpNotificationChannel.Find(channelName) is always returning null (that's why the app is always generating a new URI).

I already read this, but still didn't help me.

So, my question is:

  • Shouldn't HttpNotificationChannel.Find(channelName) returns something different from 'null' if the app had already generated a channel?

If I missed something that could help, please tell me.

Community
  • 1
  • 1

1 Answers1

0

I went through your post and the mentioned links. It seems channelUri updation is pretty random (usually it would certainly change for app uninstall/install, but there maybe other scenarios as well). One sure-shot way of ensuring your users are targeted properly is to associate the channelUri with another unique identifier. For instance, after grabbing the channelUri you might want to update the server database with the uri and a unique user id. For subsequest calls, only the channel may be updated for the same user. Hope this helps a bit.

PhoBi
  • 36
  • 3