我正在编写一个使用推送通知的Windows Phone 7应用程序,并且有一个类负责管理MS Notification Server与我在云中的服务之间的交互.但是,当我试图在我的设备上打开频道时,HttpNotificationChannel会抛出InvalidOperationException,并显示消息"无法打开频道".根据MSDN, 我应该尝试再次打开频道.
我打开推送通知的代码段遵循标准模式;
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));
};
}
}
Run Code Online (Sandbox Code Playgroud)
我不确定MSDN的意思是"尝试再次打开频道".我已经在try/catch中调用了Open(),并在两次尝试之间暂停5秒,但是没有成功.我也尝试了相同的方法围绕整个方法(即每次抛出时调用HttpNotificationChannel.Find())无济于事.
我知道这有点模糊 - 但是想知道是否有人有任何处理这个的建议?这个相同的代码在模拟器中完美运行,但每次在我的实际设备上都会失败,即使在我的应用程序未安装和重新安装之后也是如此.鉴于这是我的实际手机,我有点保持沉默,希望它解决了这个问题,并且不愿意将此应用程序发布到市场,因为这个问题困扰着我.
更新:另外一点,我使用的是未经身份验证的渠道,因此我的基于云的服务没有安装证书.
更新#2:此外,我刚尝试将Microsoft Phone Push Recipe部署到我的设备上,它也抛出相同的异常.