windows-phone-7 - Wp7 :Push notification channel URI is null

标签 windows-phone-7 push-notification mpns

我们正在尝试使用文档如何:为 Windows Phone 设置通知 channel 中的最新代码来测试推送通知

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,它会打开一个新 channel ,但永远不会触发 ChannelUriUpdated 事件。

如果 HttpNotificationChannel.Find() 返回一个 channel ,则 ChannelUri 属性为 null。示例代码在此处崩溃,因为它假定 ChannelUri 属性不为 null。

两种情况都不会触发 ErrorOccurred 事件。

我该如何解决这个问题?这个问题是因为微软服务器还是其他原因?

提前致谢

编辑 等待重播,十天后我遇到了 null uri 问题 任何人都可以告诉我如何解决这个问题,有时 MSPN 服务器有时会给出 chanalk uri ans 不是我的意思是有时它会给出空引用异常。 微软在做什么?

最佳答案

如果我没弄错的话,www.contoso.com 是一个示例 URI,用于演示您需要放置自己的服务器 URL 地址,但根据我的经验,我从不以这种方式使用。我更喜欢只放

myChannel = new HttpNotificationChannel("MyChannel");

看这个example (它是西类牙语)但是代码非常清楚你需要做什么来设置推送通知客户端和服务。

希望对你有所帮助。

关于windows-phone-7 - Wp7 :Push notification channel URI is null,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15607389/

相关文章:

c# - 如何在 MVVM 模型中管理磁贴用户控件(具有列表框绑定(bind))?

ios - 如何检测用户卸载的 iOS App?我需要推送严重通知。我不想失去它

android - Web 推送通知在 Apache Cordova Android 应用程序中工作吗?

c# - 是否可以从 WP7 应用程序导航到设备设置?

c# - 继承自 IEnumerable

android - 广播接收器推送通知

push-notification - 了解 Windows Phone 8.1 的推送通知

windows-phone-7 - Windows Phone 7 - 如何从/向应用程序发送文件?

azure - 带有有效负载的 Windows Phone toast 通知模板

windows-phone-7 - NavigationService 抛出 NullReferenceException