Get error when get the push uri

Category: windows phone push

Question

JoelJay on Thu, 24 Oct 2013 09:12:14


 When I get open the channel I got the error:

“The channel does not exist, but could not be opened.  Try opening the channel again.”

I tested the code with the Device of Lumia 920. It was fine for a long time, but it did't work suddenly. And it did't work again.

Here is the code I used:

 HttpNotificationChannel pushChannel;

// The name of our push channel.
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);

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

}

Replies

Eric Fleck on Thu, 24 Oct 2013 18:10:34


During app development and testing cycles it is possible to 'leak' channels... it could be that you have hit some limit.  There is logic in the phone boot up sequence to clean up these orphaned channels so I would try turning your phone off and back on again to see if that helps. 

JoelJay on Fri, 25 Oct 2013 02:15:57


Hi Eric,

 I tried close the phone and restart it several times. But it seems did't work at all.

Eric Fleck on Fri, 25 Oct 2013 14:25:05


Have you noticed any problem with push notifications in other applications on the same phone?

To get an idea if this problem is specific to that App / project, or if it is a general problem on that phone I would try deploying a second app which uses Push notification, like one of the push samples, to see if that app experiences the same problem on that phone.

If a second app project works ok then try manually uninstalling the first project and power cycle the phone again.  When the phone boots up again plug it into a power source and allow it to sit idle for a few minutes... to allow ample time for any background cleanup processes to complete.

FYI: when switching from a USB charger connection to a USB PC connection you may experience a problem in which the phone is not detected, simple disconnect the USB from the PC, wait a few seconds and reconnect.

JoelJay on Tue, 29 Oct 2013 04:04:07


Thanks for reply. Even the push sample can't not work. But the app which is installed in the device for a long time can work. Any new deployed app cann't get the Uri. 

There is something I have to say. There is another device which had the same problem, but when I Recharged this device after a few days of out of power. It can get the Uri.

Maybe I should try the same way to The Lumia 920.

Eric Fleck on Tue, 29 Oct 2013 13:41:15


If the device is just for testing then I would factory reset to quickly get back to a working state but that is not such a good option if you also use the device as your personal phone.

  You could try alternately disabling the cellular data and WiFi connection to see if it works when only one data option is available.

  In the anecdote about your other device, a few days probably would not cause channels to expire but might be enough to cause it to discard an IP address and get a new one.  Also, ensuring the device is fully charged also helps since the battery saver feature can disable push notifications when the battery gets too low.