简体   繁体   中英

Unable to send Windows Phone push notification using Azure.NotificationHubs SDK

I'm using Microsoft.Azure.NotificationHubs SDK v1.0.8 to integrate with the azure notification hub and send pushes. While iOS and Android work just fine, my Windows Phone pushes stop working some time ago. There the payload I use:

<?xml version="1.0" encoding="utf-8"?>
<wp:Notification xmlns:wp="WPNotification">
   <wp:Toast>
    <wp:Text1>Notification Title</wp:Text1>
    <wp:Text2>Notification Text!</wp:Text2>
    <wp:Param>?param1=value1&param2=value2</wp:Param>
   </wp:Toast>
</wp:Notification>

And here is the error I'm getting:

System.ArgumentException: The payload is not in accepted XML format. The first node should be Tile/Toast. If want to send raw notification, please set "X-NotificationClass" to "3" in header. at Microsoft.Azure.NotificationHubs.RegistrationSDKHelper.DetectMpnsTemplateRegistationType(String body, String errorMsg)

I tried to send the push directly from the azure portal or visual studio - it works fine. So the issue is somewhere in the SDK I guess.

This guide shows how to send the same notification using regular web request and special headers are set to send toast

sendNotificationRequest.Headers.Add("X-WindowsPhone-Target", "toast");
sendNotificationRequest.Headers.Add("X-NotificationClass", "2");

With the Azure SDK I have no way to setup these headers and can use only the following method to send my payload which gives me the error above:

await Hub.SendMpnsNativeNotificationAsync(payload, userIdTag);

What could be wrong in my setup here?

The issues was in this line

<wp:Param>?param1=value1&param2=value2</wp:Param>

& value should be encoded so xml could be properly parsed by the Azure Notification Hub SDK, so I changed it to

<wp:Param>?param1=value1&amp;param2=value2</wp:Param>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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