c# - Azure 通知中心错误 401

标签 c# azure google-cloud-messaging apple-push-notifications azure-notificationhub

我在设置向 iOS/Android 设备发送推送通知的控制台应用程序时遇到了一些问题。

错误如下所示:

Unhandled Exception: System.AggregateException: One or more errors
occurred. ---System.UnauthorizedAccessException: The remote server
returned an error: (401)
Unauthorized..TrackingId:ea158550-8761-41f8-821d-dbcb88fcce56,TimeStamp:18/07/2016
08:58:21 ---System.Net.WebException: The remote server returned an
error: (401) Unauthorized.    at
System.Net.HttpWebRequest.EndGetResponse(IAsyncResult asyncResult)   
at
Microsoft.Azure.NotificationHubs.NotificationRequestAsyncResult`1.<GetAsyncSteps>b__3(TAsyncResult
thisPtr, IAsyncResult r)    at
Microsoft.Azure.NotificationHubs.Messaging.IteratorAsyncResult`1.StepCallback(IAsyncResult
result)    --- End of inner exception stack trace ---

Server stack trace:


Exception rethrown at [0]:    at
Microsoft.Azure.NotificationHubs.Common.AsyncResult.End[TAsyncResult](IAsyncResult
result)    at
Microsoft.Azure.NotificationHubs.NotificationHubManager.EndSendNotification(IAsyncResult
result)    at
System.Threading.Tasks.TaskFactory`1.FromAsyncCoreLogic(IAsyncResult
iar, Func`2 endFunction, Action`1 endAction, Task`1 promise, Boolean
requiresSynchronization)    --- End of inner exception stack trace ---
at System.Threading.Tasks.Task.ThrowIfExceptional(Boolean
includeTaskCanceledExceptions)    at
System.Threading.Tasks.Task.Wait(Int32 millisecondsTimeout,
CancellationToken cancellationToken)    at
System.Threading.Tasks.Task.Wait()    at
XamarinAzurePushNotification.Server.Program.Main(String[] args) in
B:\Personal Development\Visual Studio
2015\AzurePushNotifications\XamarinAzurePushNotification.Server\Program.cs:line
26

这是我的控制台应用程序代码:

private static void Main(string[] args)
{
    var hub = NotificationHubClient.CreateClientFromConnectionString("Endpoint=sb://ConnectionStringName.servicebus.windows.net/;SharedAccessKeyName=DefaultListenSharedAccessSignature;SharedAccessKey=ConnectionStringKey", "HubName");

    var iOS_alert = "{\"aps\":{\"alert\":\"Hello. This is a iOS notification! Tada!\", \"sound\":\"default\"}}";
    hub.SendAppleNativeNotificationAsync(iOS_alert).Wait();

    var android_alert = "{\"message\": \"Can I interest you in a once in a lifetime push notification?!\", \"title\":\"Ding, dong!\"}";
    hub.SendGcmNativeNotificationAsync(android_alert).Wait();

    Console.WriteLine("MESSAGE SENT");
}

如果有人能帮我解决这个问题,那就太好了。

最佳答案

看起来您正在使用DefaultListenSharedAccessSignature;而是使用 DefaultFullSharedAccessSignature

关于c# - Azure 通知中心错误 401,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38432754/

相关文章:

android - 一旦应用程序在 Android 中的小米和联想设备上被杀死,就不会收到 GCM 通知

c# - 如何使用表达式生成此属性实现而不是发出 IL?

c# - 使用 AutoFixture 自定义显式设置样本的多个属性

c# - ASP.NET 使用 SqlConnection 连接 MySQL

使用构建工件以编程方式部署 Web 应用程序 zip 包的 Azure Arm 模板

php - GCM 与 PHP(谷歌云消息)

c# - 使数据库 mdf 跨不同计算机工作

azure - 来自 Azure IOT 中心的 SMS 消息传递

azure - 从另一个管道 Azure 下载管道工件

android - 在 Applozic 的 Messaging SDK 中将 Intent 添加到类中