Search code examples
c#azurepush-notificationazureservicebusmpns

Azure NotificationHubClient Breaking PNS Handle


We are trying to use the NotificationHubClient in Microsoft.ServiceBus.Notifications. We are having a strange problem which the code below shows where we register the Device like so:

NotificationHubClient client = GetHubclient();

  var task = client.CreateMpnsNativeRegistrationAsync(deviceToken, tags);
  Task.WaitAll(task);

This registers the device fine and if we send a test toast message from the azure portal debug page it comes through to the windows phone without issue. However if we call the following:

var sentTask = client.SendMpnsNativeNotificationAsync(GetPayload());
Task.WaitAll(sentTask);


private static string GetPayload()
{
  return "<wp:Notification xmlns:wp=\"WPNotification\"><wp:Toast><wp:Text1>Great News</wp:Text1><wp:Text2>Great News</wp:Text2></wp:Toast></wp:Notification>";
}

No toast notification arrives on the phone and if we then go and try to send a test toast notification again from the debug page of the azure portal it no longer works and the following error is displayed:

The Push Notification System handle for the registration is invalid

None of this is making sense, we have enabled testSend and there are no errors coming back from the client in the code, in fact it says everything was successful the first time even though this appears to break the PNS handle.

Has anyone come across this before?


Solution

  • It turns out that if the Xml declarations are missing:

    <?xml version="1.0" encoding="utf-8"?>
    

    Then you can no longer send push notifications to any phones you tried to send a push notification to as it is invalidated. This seems pretty awful, sure don't send the notification if the payload is invalid but why invalidate the PNS.