【发布时间】:2013-03-14 11:54:52
【问题描述】:
我们正在尝试使用文档中的最新代码测试推送通知如何:为 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 事件。
我该如何解决这个问题?这个问题是因为微软服务器还是其他什么原因?
提前致谢
编辑 等待重播,十天后我遇到了 null uri 问题 任何人都可以告诉我如何在某个时候 MSPN 服务器给 chanalk uri ans 解决这个问题,而不是我的意思是某个时候它给空引用异常。 微软在做什么?
【问题讨论】:
标签: windows-phone-7 push-notification mpns