我们正在尝试测试推送通知,使用文档中的最新代码如何:为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服务器给出通道uri,有时不是,我的意思是有时它给出空引用异常。微软在做什么?
如果我没有出错,www.contoso.com这是一个示例URI,用于演示您需要放置自己的服务器URL地址,但根据我的经验,我从未以这种方式使用过。我更喜欢写
myChannel = new HttpNotificationChannel("MyChannel");
看这个例子(它是西班牙语的),但是代码非常清楚你需要做什么来设置推送通知客户端和服务。
我希望我帮到你了。
你正在测试什么移动模拟器,你有windows手机开发的开发者账户订阅吗?如果开发者解锁了你的手机,
Noorul。
根据文档,我认为问题是您正在使用经过身份验证的web服务的HttpNotificationChannel
构造函数。
/// 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);
...
}
希望有所帮助