Windows phone 8 在具有推送通知功能的Windows Phone 8应用程序中未接收到URI

Windows phone 8 在具有推送通知功能的Windows Phone 8应用程序中未接收到URI,windows-phone-8,push-notification,mpns,Windows Phone 8,Push Notification,Mpns,我正在使用以下工具在Windows 8 Phone上开发应用程序 using System; using System.Windows; using Microsoft.Phone.Controls; using Microsoft.Phone.Notification; namespace sdkRawNotificationCS { public partial class MainPage : PhoneApplicationPage { // Mai

我正在使用以下工具在Windows 8 Phone上开发应用程序

using System;
using System.Windows;
using Microsoft.Phone.Controls;
using Microsoft.Phone.Notification;


namespace sdkRawNotificationCS
{
    public partial class MainPage : PhoneApplicationPage
    {

        // MainPage constructor
        public MainPage()
        {
           /// Holds the push channel that is created or found.
           HttpNotificationChannel pushChannel;

           // The name of our push channel.
           string channelName = "RawSampleChannel";

           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);
             pushChannel.HttpNotificationReceived += new EventHandler<HttpNotificationEventArgs>(PushChannel_HttpNotificationReceived);

             pushChannel.Open();

           }
           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);
             pushChannel.HttpNotificationReceived += new EventHandler<HttpNotificationEventArgs>(PushChannel_HttpNotificationReceived);

             // Display the URI for testing purposes.
             System.Diagnostics.Debug.WriteLine(pushChannel.ChannelUri.ToString());
             MessageBox.Show(String.Format("Channel Uri is {0}",
                pushChannel.ChannelUri.ToString()));

           }
       }

       // Event handler for when the push channel Uri is updated.
       void PushChannel_ChannelUriUpdated(object sender, NotificationChannelUriEventArgs e)
       {

          Dispatcher.BeginInvoke(() =>
          {
             // Display the new URI for testing purposes.
             System.Diagnostics.Debug.WriteLine(e.ChannelUri.ToString());
             MessageBox.Show(String.Format("Channel Uri is {0}",
                e.ChannelUri.ToString()));

         });
     }


     // Event handler for when a push notification error occurs.
     void PushChannel_ErrorOccurred(object sender, NotificationChannelErrorEventArgs e)
     {
        // Error handling logic for your particular application would be here.
        Dispatcher.BeginInvoke(() =>
            MessageBox.Show(String.Format("A push notification {0} error occurred.  {1} ({2}) {3}",
                e.ErrorType, e.Message, e.ErrorCode, e.ErrorAdditionalData))
                );
     }

     // Event handler for when a raw notification arrives.  For this sample, the raw 
     // data is simply displayed in a MessageBox.
     void PushChannel_HttpNotificationReceived(object sender, HttpNotificationEventArgs e)
     {
        string message;

        using (System.IO.StreamReader reader = new System.IO.StreamReader(e.Notification.Body))
        {
            message = reader.ReadToEnd();
        }


        Dispatcher.BeginInvoke(() =>
            MessageBox.Show(String.Format("Received Notification {0}:\n{1}",
                DateTime.Now.ToShortTimeString(), message))
                );
     }
 }
}
使用系统;
使用System.Windows;
使用Microsoft.Phone.Controls;
使用Microsoft.Phone.Notification;
命名空间sdkRawNotificationCS
{
公共部分类主页:PhoneApplicationPage
{
//主页构造函数
公共主页()
{
///保存已创建或找到的推送通道。
HttpNotificationChannel推送通道;
//我们推送频道的名称。
字符串channelName=“RawSampleChannel”;
初始化组件();
//试着找到推送通道。
pushChannel=HttpNotificationChannel.Find(channelName);
//如果未找到通道,则创建到推送服务的新连接。
if(pushChannel==null)
{
pushChannel=新的HttpNotificationChannel(通道名称);
//在尝试打开通道之前注册所有事件。
pushChannel.ChannelUriUpdated+=新事件处理程序(pushChannel\u ChannelUriUpdated);
pushChannel.ErrorOccursed+=新的事件处理程序(pushChannel\u ErrorOccursed);
pushChannel.HttpNotificationReceived+=新事件处理程序(pushChannel\u HttpNotificationReceived);
pushChannel.Open();
}
其他的
{
//频道已经打开,所以只需注册所有事件。
pushChannel.ChannelUriUpdated+=新事件处理程序(pushChannel\u ChannelUriUpdated);
pushChannel.ErrorOccursed+=新的事件处理程序(pushChannel\u ErrorOccursed);
pushChannel.HttpNotificationReceived+=新事件处理程序(pushChannel\u HttpNotificationReceived);
//显示URI以进行测试。
System.Diagnostics.Debug.WriteLine(pushChannel.ChannelUri.ToString());
Show(String.Format(“通道Uri为{0}”),
pushChannel.ChannelUri.ToString());
}
}
//更新推送通道Uri时的事件处理程序。
void PushChannel\u ChannelUriUpdated(对象发送方,NotificationChannelUriEventArgs e)
{
Dispatcher.BeginInvoke(()=>
{
//显示新URI以进行测试。
System.Diagnostics.Debug.WriteLine(例如ChannelUri.ToString());
Show(String.Format(“通道Uri为{0}”),
e、 ChannelUri.ToString());
});
}
//发生推送通知错误时的事件处理程序。
出现无效PushChannel_错误(对象发送方,NotificationChannelErrorEventArgs e)
{
//这里将显示特定应用程序的错误处理逻辑。
Dispatcher.BeginInvoke(()=>
MessageBox.Show(String.Format)(“发生推送通知{0}错误。{1}({2}){3}”,
e、 ErrorType,e.Message,e.ErrorCode,e.ErrorAdditionalData)
);
}
//原始通知到达时的事件处理程序
//数据只显示在消息框中。
无效PushChannel_HttpNotificationReceived(对象发送方,HttpNotificationEventArgs e)
{
字符串消息;
使用(System.IO.StreamReader=new System.IO.StreamReader(e.Notification.Body))
{
message=reader.ReadToEnd();
}
Dispatcher.BeginInvoke(()=>
MessageBox.Show(String.Format(“收到的通知{0}:\n{1}”),
DateTime.Now.ToSortTimeString(),消息)
);
}
}
}
我面临的问题是,当我运行应用程序时,我无法在事件处理程序PushChannel\u ChannelUriUpdated中获取任何ChannelURI。运行代码时没有给出错误。此外,未调用事件处理程序PushChannel\u ErrorOccursed


请建议出了什么问题?

您有什么错误可以与我们分享吗?@Eran。。。不,我没有收到任何错误。。。