1

我在設置控制檯應用程序時會遇到一些問題,它會向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"); 
} 

如果任何人都可以給我個忙。這將會是巨大的。

+0

您可以驗證您的API密鑰是否是服務器密鑰?看到我的[在這裏回答](http://stackoverflow.com/a/37801206/4625829)。 –

+0

您看到我已通過使用測試推送通知函數在我的應用程序中測試了我的應用程序,並且我的應用程序正在接收通知,但是當我試圖在控制檯應用程序(服務器)中實現它時,它只是給出了該錯誤。 – ADuggan

+0

我剛剛在那裏檢查,似乎我已經在使用服務器密鑰。 – ADuggan

回答

4

看起來你正在使用DefaultListenSharedAccessSignature;改爲使用DefaultFullSharedAccessSignature

相關問題