I am writing a Windows Phone 7 application that uses Push Notifications and has a class that is responsible for managing the interaction between MS notification servers and my service in the cloud. However, when I try to open a channel on my device, the HttpNotificationChannel throws an InvalidOperationException with the message "Could not open channel." According to MSDN I have to try to reopen the channel.
My code snippet for opening push notifications follows standard templates:
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();
I'm not sure exactly what MSDN means, "try opening the channel again." I wrapped the Open () call in try / catch and snoozing for 5 seconds between attempts, but this failed. I also tried the same approach throughout the method (i.e., did the HttpNotificationChannel.Find () call every time it throws) to no avail.
I know this is a bit vague, but I was wondering if anyone has any suggestions on this? The same code works flawlessly in the emulator, but does not work every time on my device itself even after installing and reinstalling my application. Given that this is my actual phone, I am a little restrained to make the hardware reset in the hope that it solves this problem and does not feel comfortable releasing the application to the market when this problem haunts me.
Update: an additional point, I use a channel that has not been verified, so a certificate is not installed for my cloud service.
Update # 2: In addition, I just tried deploying Microsoft Phone Push Recipe to my device, and also threw the same exception.
c # windows-phone-7 push-notification mpns
MrMDavidson
source share