我们正在尝试使用文档 How to: Set Up a Notification Channel for Windows Phone 中的最新代码来测试推送通知
public HttpNotificationChannel myChannel;
public void CreatingANotificationChannel()
{
myChannel = HttpNotificationChannel.Find("MyChannel");
if (myChannel == null)
{
myChannel = new HttpNotificationChannel("MyChannel","www.contoso.com");
// An application is expected to send its notification channel URI to its corresponding web service each time it launches.
// The notification channel URI is not guaranteed to be the same as the last time the application ran.
myChannel.ChannelUriUpdated += new EventHandler<NotificationChannelUriEventArgs>(myChannel_ChannelUriUpdated);
myChannel.Open();
}
else // Found an existing notification channel.
{
// The URI that the application sends to its web service.
Debug.WriteLine("Notification channel URI:" + myChannel.ChannelUri.ToString());
}
myChannel.HttpNotificationReceived += new EventHandler<HttpNotificationEventArgs>(myChannel_HttpNotificationReceived);
myChannel.ShellToastNotificationReceived += new EventHandler<NotificationEventArgs>(myChannel_ShellToastNotificationReceived);
myChannel.ErrorOccurred += new EventHandler<NotificationChannelErrorEventArgs>(myChannel_ErrorOccurred);
}
如果 HttpNotificationChannel.Find() 返回 null,它会打开一个新通道,但不会触发 ChannelUriUpdated 事件。
如果 HttpNotificationChannel.Find() 返回通道,则 ChannelUri 属性为空。示例代码在此处崩溃,因为它假定 ChannelUri 属性不为空。
在这两种情况下都不会触发 ErrorOccurred 事件。
我怎么解决这个问题?这个问题是因为微软服务器还是其他什么?
提前致谢
编辑 等待重播,十天后我遇到了空 uri 问题,谁能告诉我如何在某个时候解决这个问题 MSPN 服务器给 chanalk uri ans 不是我的意思是某个时候它给空引用异常。微软在做什么?