Azure通知集线器错误401
问题描述:
我在设置控制台应用程序时会遇到一些问题,它会向iOS/Android设备发送推送通知。显示Azure通知集线器错误401
误差如下:
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
。
您可以验证您的API密钥是否是服务器密钥?看到我的[在这里回答](http://*.com/a/37801206/4625829)。 –
您看到我已通过使用测试推送通知函数在我的应用程序中测试了我的应用程序,并且我的应用程序正在接收通知,但是当我试图在控制台应用程序(服务器)中实现它时,它只是给出了该错误。 – ADuggan
我刚刚在那里检查,似乎我已经在使用服务器密钥。 – ADuggan