0

我想從桌面Windows應用程序發送Windows Phone 8.1的推送通知。如何從Windows應用程序發送推送通知

我發現這個例子:

private static async void SendNotificationAsync() 
    { 
     // Define the notification hub. 
     NotificationHubClient hub = 
      NotificationHubClient.CreateClientFromConnectionString(
       "Endpoint=sb://...notificationhub-ns.servicebus.windows.net/;SharedAccessKeyName=DefaultFullSharedAccessSignature;SharedAccessKey=9w3Mo....NNcDRI=", "MinskTransNotificationBeta"); 

     // Create an array of breaking news categories. 
     var categories = new string[] { "World", "Politics", "Business", 
    "Technology", "Science", "Sports"}; 

     foreach (var category in categories) 
     { 
      try 
      { 
       // Define a Windows Store toast. 
       //var wnsToast = "<toast><visual><binding template=\"ToastText01\">" 
       // + "<text id=\"1\">Breaking " + category + " News!" 
       // + "</text></binding></visual></toast>"; 
       //await hub.SendWindowsNativeNotificationAsync(wnsToast, category); 

       // Define a Windows Phone toast. 
       var mpnsToast = 
        "<?xml version=\"1.0\" encoding=\"utf-8\"?>" + 
        "<wp:Notification xmlns:wp=\"WPNotification\">" + 
         "<wp:Toast>" + 
          "<wp:Text1>Breaking " + category + " News!</wp:Text1>" + 
         "</wp:Toast> " + 
        "</wp:Notification>"; 
       await hub.SendMpnsNativeNotificationAsync(mpnsToast, category); 


      } 
      catch (ArgumentException) 
      { 
       // An exception is raised when the notification hub hasn't been 
       // registered for the iOS, Windows Store, or Windows Phone platform. 
      } 
     } 
    } 

,但我得到的異常在此終結NOTFOUND

An exception of type 'Microsoft.ServiceBus.Messaging.MessagingEntityNotFoundException' occurred in mscorlib.dll but was not handled in user code

Additional information: The remote server returned an error: (404) Not Found. No service is hosted at the specified address..TrackingId:7443c7a8-....c03f7da9_G4,TimeStamp:6/1/2015 9:22:48 PM

回答

0

檢查服務。

最可能是連接字符串中的錯誤。

0

檢查

  • 啓用從Azure的門戶網站未經身份驗證的推送通知。
  • 檢查您的連接字符串,並確保您使用的是FullSharedAccesKey。(您的SAS名稱必須匹配連接字符串中的字符串)
  • 您有互聯網連接。
相關問題