Wp7:推送通知通道URI为空

时间:2013-03-25 03:59:17

标签: windows-phone-7 push-notification mpns

我们正在尝试使用文档中的最新代码测试推送通知如何:为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属性为null。示例代码在这里崩溃,因为它假定ChannelUri属性不为null。

在任何情况下都不会触发ErrorOccurred事件。

我该如何解决这个问题?这个问题是因为微软服务器或其他任何东西?

事先提前

修改 等待重播,十天后我遇到了无效的uri问题 任何人都可以告诉我如何解决这个问题一段时间MSPN服务器提供通信uri ans一段时间不是我的意思,有一段时间它给空引用异常。 微软在做什么?

3 个答案:

答案 0 :(得分:1)

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

myChannel = new HttpNotificationChannel("MyChannel");

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

我希望我帮助过你。

答案 1 :(得分:0)

您正在测试什么手机是模拟器, 您是否拥有Windows Phone开发的开发者帐户订阅, 如果开发人员解锁了您的手机,

Noorul。

答案 2 :(得分:0)

根据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);
    ...
}

希望有所帮助