0

我正在尝试向使用 VS 2013 Express 在我的笔记本电脑上开发的 Windows 应用商店应用发送推送通知。现在已经有几天了,但我无法弄清楚为什么我得到“从令牌提供者获得的令牌是错误的”错误。为此,我使用 Windows Azure 通知总线。我使用 VS Server Explorer 来发送测试通知。我也可以在“设备注册”选项卡中看到我的笔记本电脑正在注册为设备。我也尝试了 Azure 门户,但同样的错误。但是,当我尝试连接到提供连接字符串的 Service Bus Explorer 2.4.3.0 时,它会抛出以下错误。<21:47:14> 异常:远程服务器返回错误:(401) 未经授权。此操作需要管理声明。TrackingId:c0c4fea2-08bc-4def-964c-ec6e690b7551_G45,TimeStamp:10/12/2014 4:17:11 PM。方法 b__7e:重试 10 次中的 2 次。

仅供参考:我正在逐步关注下面的文章。 http://azure.microsoft.com/en-us/documentation/articles/notification-hubs-windows-store-dotnet-get-started/

请帮我。谢谢你。马赫什

4

1 回答 1

0

看起来令牌刚刚过期。确保每次应用程序启动时都获得令牌。就您引用的文章而言,这意味着您应该调用方法 InitNotificationsAsync() 来执行此操作。这是那个方法:

private async void InitNotificationsAsync()
{
    var channel = await PushNotificationChannelManager.CreatePushNotificationChannelForApplicationAsync();

    var hub = new NotificationHub("<hub name>", "<connection string with listen access>");              
    var result = await hub.RegisterNativeAsync(channel.Uri);

    // Displays the registration ID so you know it was successful
    if (result.RegistrationId != null)
    {
        var dialog = new MessageDialog("Registration successful: " + result.RegistrationId);
        dialog.Commands.Add(new UICommand("OK"));
        await dialog.ShowAsync();
    }

}
于 2014-10-13T22:26:15.723 回答