该 URI 称为通知通道,它是 APNS 设备令牌和 GCM 注册 ID 的 MPNS 等效项。您可以在您的 Windows Phone 应用程序代码中获取它:
public MainPage()
{
/// Holds the push channel that is created or found.
HttpNotificationChannel pushChannel;
// The name of our push channel.
string channelName = "ToastSampleChannel";
InitializeComponent();
// 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);
// Register for all the events before attempting to open the channel.
pushChannel.ChannelUriUpdated += new EventHandler<NotificationChannelUriEventArgs>(PushChannel_ChannelUriUpdated);
pushChannel.ErrorOccurred += new EventHandler<NotificationChannelErrorEventArgs>(PushChannel_ErrorOccurred);
// Register for this notification only if you need to receive the notifications while your application is running.
pushChannel.ShellToastNotificationReceived += new EventHandler<NotificationEventArgs>(PushChannel_ShellToastNotificationReceived);
pushChannel.Open();
// Bind this new channel for toast events.
pushChannel.BindToShellToast();
}
else
{
// The channel was already open, so just register for all the events.
pushChannel.ChannelUriUpdated += new EventHandler<NotificationChannelUriEventArgs>(PushChannel_ChannelUriUpdated);
pushChannel.ErrorOccurred += new EventHandler<NotificationChannelErrorEventArgs>(PushChannel_ErrorOccurred);
// Register for this notification only if you need to receive the notifications while your application is running.
pushChannel.ShellToastNotificationReceived += new EventHandler<NotificationEventArgs>(PushChannel_ShellToastNotificationReceived);
// Display the URI for testing purposes. Normally, the URI would be passed back to your web service at this point.
System.Diagnostics.Debug.WriteLine(pushChannel.ChannelUri.ToString());
MessageBox.Show(String.Format("Channel Uri is {0}",
pushChannel.ChannelUri.ToString()));
}
}
您不必验证您的网络服务(未经验证的网络服务可以每天每台设备发送 500 条消息),但建议这样做:
我们建议设置经过身份验证的 Web 服务以将您的通知发送到推送通知服务,因为通过 HTTPS 接口进行通信以提高安全性。经过身份验证的 Web 服务对它们可以发送的推送通知的数量没有每日限制。另一方面,未经身份验证的 Web 服务以每天每个订阅 500 条推送通知的速度受到限制。有关详细信息,请参阅设置经过身份验证的 Web 服务以发送 Windows Phone 的推送通知。
相关链接:
为 Windows Phone 发送推送通知
设置经过身份验证的 Web 服务以发送 Windows Phone 的推送通知