I'm writing a Windows Phone 7 application which utilises Push Notifications and have a class which is responsible for managing interactions between the MS Notification Servers and my service in the cloud. However when I'm attempting to open the channel on my device HttpNotificationChannel is throwing an InvalidOperationException with the message "Failed to open channel". According to MSDN I should try opening the channel again.
My snippet of code to open the push notification is following the standard pattern of;
public class HttpNotification {
private const string kChannelName = "MyApp.PushNotification";
private HttpNotificationChannel _Channel;
public void Register() {
try {
_Channel = HttpNotificationChannel.Find(kChannelName);
if (_Channel == null) {
_Channel = new HttpNotificationChannel(kChannelName);
InstallEventHandlers();
// This line throws
_Channel.Open();
} else {
InstallEventHandlers();
};
} catch (InvalidOperationException ex) {
MessageBox.Show(string.Format("Failed to initialise Push Notifications - {0}", ex.Message));
};
}
}
I'm not sure exactly what MSDN means by "try opening the channel again". I've wrapped the call to Open() in a try/catch and snoozing 5 seconds between attempts but it doesn't succeed. I've also tried the same approach around the entire method (ie. Do the call to HttpNotificationChannel.Find() each time it throws) to no avail.
I know this is a tad bit vague - but was wondering if anyone has any suggestions on handling this? This same code works flawlessly in the emulator, but fails every time on my actual device, even after an un-install and re-install of my application. Given that this is my actual phone, I'm a little reticent to do a hardware reset in the hope that it solves this issue, and don't feel comfortable releasing the application to the marketplace with this issue haunting me.
Update: An additional point, I'm using an unauthenticated channel, so there's no certificate installed for my cloud-based service.
Update #2: Further, I just tried deploying the Microsoft Phone Push Recipe to my device and it's also throwing the same exception.
@slaad .. here are few things that I would check, unless you have already tried these:
Sorry, not being of much more help than this.