繁体   English   中英

Azure通知中心错误401

[英]Azure Notification Hub error 401

我在设置控制台应用程序时遇到了问题,该应用程序会将推送通知发送到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

如果以上任何答案均无效,请检查服务器/ PC是否配置了正确的日期时间。 在我的情况下,在客户端上,服务器的日期时间设置错误,并且出现错误:

错误代码:0x17 System.AggregateException:发生一个或多个错误。 ---> System.UnauthorizedAccessException:远程服务器返回错误:(401)未经授权。 ExpiredToken:.TrackingId:4c2cdbg3-e1a8-4240-b963-d6f55e8f2c76_G29,TimeStamp:8/23/2018 8:58:27 AM ---> System.Net.WebException:远程服务器返回错误:(401)未经授权。 在Microsoft.Azure.NotificationHubs.NotificationRequestAsyncResult 1.<>c.<GetAsyncSteps>b__26_3(TAsyncResult thisPtr, IAsyncResult r) at Microsoft.Azure.NotificationHubs.Messaging.IteratorAsyncResult在System.Net.HttpWebRequest.EndGetResponse(IAsyncResult asyncResult)处在Microsoft.Azure.NotificationHubs.Messaging.ItbackAsyncResult 1.<>c.<GetAsyncSteps>b__26_3(TAsyncResult thisPtr, IAsyncResult r) at Microsoft.Azure.NotificationHubs.Messaging.IteratorAsyncResult1.<>c.<GetAsyncSteps>b__26_3(TAsyncResult thisPtr, IAsyncResult r) at Microsoft.Azure.NotificationHubs.Messaging.IteratorAsyncResult (IAsyncResult结果)-内部异常堆栈跟踪的结尾-

直到发现问题之前,我都很沮丧。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM