【问题标题】:Wp7:Push notification channel URI is nullWp7:推送通知通道 URI 为空
【发布时间】: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


    【解决方案1】:

    根据documentation,我认为问题在于您正在使用经过身份验证的Web服务的HttpNotificationChannel构造函数。

    相反,您应该使用只接受一个参数的构造函数,因为您可以检查this example

    /// Holds the push channel that is created or found.
    HttpNotificationChannel pushChannel;
    
    // The name of our push channel.
    string channelName = "ToastSampleChannel";
    
    // Try to find the push channel.
    pushChannel = HttpNotificationChannel.Find(channelName);
    
    // If the channel was not found, then create a new connection to the push service.
    if (pushChannel == null)
    {
        pushChannel = new HttpNotificationChannel(channelName);
        ...
    }
    

    希望对你有帮助

    【讨论】:

      【解决方案2】:

      您正在测试什么是模拟器, 你有windows phone开发的开发者账号订阅吗, 如果您的开发者解锁了您的手机,

      诺鲁尔。

      【讨论】:

      • :我正在用手机测试这个演示,是的,我有开发者帐户,如果你开发者解锁了你的手机,
      【解决方案3】:

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

      myChannel = new HttpNotificationChannel("MyChannel");
      

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

      希望对你有所帮助。

      【讨论】:

      • 感谢重播,我正在使用类似 myChannel = new HttpNotificationChannel("MyChannel");但一段时间不工作 uri 触发空引用异常
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-10-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多