C# Windows Phone silverlight 8.1 HttpNotificationChannel频道更新未命中

C# Windows Phone silverlight 8.1 HttpNotificationChannel频道更新未命中,c#,silverlight,push-notification,windows-phone-8.1,C#,Silverlight,Push Notification,Windows Phone 8.1,我有一个非常基本的Windows Phone Silverlight 8.1应用程序,其中包含以下内容(在将其添加到一个更大的现有应用程序之前,我想证明这个概念): HttpNotificationChannel推送通道; 无效注册表PushChannel() { pushChannel=HttpNotificationChannel.Find(channelName); //如果未找到通道,则创建到推送服务的新连接。 if(pushChannel==null) { pushChannel=新的

我有一个非常基本的Windows Phone Silverlight 8.1应用程序,其中包含以下内容(在将其添加到一个更大的现有应用程序之前,我想证明这个概念):

HttpNotificationChannel推送通道;
无效注册表PushChannel()
{
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传递回web服务的代码
}
}
void PushChannel\u ChannelUriUpdated(对象发送方,NotificationChannelUriEventArgs e)
{
Dispatcher.BeginInvoke(()=>
{
//出于测试目的显示新的URI。通常,URI会在此时传递回web服务。
System.Diagnostics.Debug.WriteLine(例如ChannelUri.ToString());
Show(String.Format(“通道Uri为{0}”),
e、 ChannelUri.ToString());
});
}
问题是PushChannel\u ChannelUriUpdated从未被击中,我就是不明白为什么

我在WMAppManifest.xml中设置了ID\u CAP\u PUSH\u通知,并且
Toast Capable=在我的包中是。appmanifest…我遗漏了什么运动鞋?

我尝试了以下通知代码:

HttpNotificationChannel pushChannel;
将pushChannel作为globle放入App.xaml.cs文件中,它在
EventHandler

string channelName = "PushChannel";
pushChannel = HttpNotificationChannel.Find(channelName);
//Push Notifications
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.enter code here
    Deployment.Current.Dispatcher.BeginInvoke(() =>
    {
        //pushURI = pushChannel.ChannelUri.ToString();
        //MessageBox.Show(String.Format("Channel Uri is {0}", pushChannel.ChannelUri.ToString()));
        Notification.ChannelURI = pushChannel.ChannelUri.ToString();
    });
}

问题出在哪里?pushChannel.Uri在pushChannel.Open()之后总是空的;连接状态断开。然后调用NotificationHub=newNotificationHub(hubName,connectionString);wait hub.RegisterNativeAsync(pushChannel.ChannelUri.ToString());它在RegisterNativeAsynchronous上抛出了一个NullReferenceException。你能试试我发布的答案吗?谢谢你-我应该更精确一些…在pushChannel.Open()之后;pushChannel Uri为空,connectionstatus已断开连接。@BzBurr我在
pushChannel\u ChannelUriUpdated
事件中获得了ChannelUriChannelUri@BzBurr请检查您的电话号码configuration@BzBurr
PushChannel\u ChannelUriUpdated
不是每次都调用,当未找到
HttpNotificationChannel
null
ID\u CAP\u PUSH\u通知打开、ID\u CAP\u网络打开、应用程序支持Toast时,会调用它……我可能缺少什么?
string channelName = "PushChannel";
pushChannel = HttpNotificationChannel.Find(channelName);
//Push Notifications
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.enter code here
    Deployment.Current.Dispatcher.BeginInvoke(() =>
    {
        //pushURI = pushChannel.ChannelUri.ToString();
        //MessageBox.Show(String.Format("Channel Uri is {0}", pushChannel.ChannelUri.ToString()));
        Notification.ChannelURI = pushChannel.ChannelUri.ToString();
    });
}
void PushChannel_ChannelUriUpdated(object sender, NotificationChannelUriEventArgs e1)
{
    try
    {
        Deployment.Current.Dispatcher.BeginInvoke(() =>
        {
            MessageBox.Show(String.Format("Channel Uri is {0}", e1.ChannelUri.ToString()));
        });
    }
    catch (Exception ex)
    { }
}
void PushChannel_ErrorOccurred(object sender, NotificationChannelErrorEventArgs e2)
{
    try
    {
        // Error handling logic for your particular application would be here.
        Deployment.Current.Dispatcher.BeginInvoke(() =>
        {
            //MessageBox.Show(String.Format("A push notification {0} error occurred.  {1} ({2}) {3}", e2.ErrorType, e2.Message, e2.ErrorCode, e2.ErrorAdditionalData));
        });
    }
    catch (Exception ex)
    { }
}