Azure WindowsPushMessage Xml有效载荷格式

时间:2016-01-12 21:04:30

标签: c# push-notification windows-phone-8.1 azure-mobile-services

在我的Azure移动服务上,我使用以下代码向Windows Phone 8.1发送推送通知:

WindowsPushMessage message = new WindowsPushMessage();
message.XmlPayload = @"<?xml version=""1.0"" encoding=""utf-8""?>" +
    @"<toast><visual><binding template=""ToastText01"">" +
    @"<text id=""1"">" + pushString + @"</text>" +
    @"</binding></visual></toast>";
try
{
    var result = await Services.Push.SendAsync(message);
    Services.Log.Info(pushString);
}
catch (System.Exception ex)
{
    Services.Log.Error(ex.Message, null, "Push.SendAsync Error");
}

我想更改通知的格式,虽然,我似乎可以找到这些格式:

WindowsPushMessage message = new WindowsPushMessage();
message.XmlPayload = "<?xml version=\"1.0\" encoding=\"utf-8\"?>" +
                "<wp:Notification xmlns:wp=\"WPNotification\">" +
                "<wp:Toast>" +
                "<wp:Text1>Yo Dawg</wp:Text1>" +
                "</wp:Toast> " +
                "</wp:Notification>";

WindowsPushMessage message = new WindowsPushMessage();
message.XmlPayload ="<wp:Notification xmlns:wp=\"WPNotification\">" +
                    "<wp:Toast>" +
                    "<wp:Text1>" + TextBoxTitle.Text.ToString() + "</wp:Text1>" +
                    "<wp:Text2>" + TextBoxSubTitle.Text.ToString() + "</wp:Text2>" +
                    "<wp:Param>/Page2.xaml?NavigatedFrom=Toast Notification</wp:Param>" +
                    "</wp:Toast> " +
                    "</wp:Notification>";

但是这些格式无法与WindowsPushMessage有效负载一起正常工作。我收到其中任何一个的错误:

The payload is not in accepted XML format. The first node should be Badge/Tile/Toast. If want to send raw notification, please set header to wns/raw.

有人能告诉我格式正确吗?

1 个答案:

答案 0 :(得分:0)

如下所示:

message.XmlPayload = @"<?xml version=""1.0"" encoding=""utf-8""?>" +
    @"<toast><visual><binding template=""ToastNewPayload"">" +
    @"<text id=""1"">" + TextBoxTitle.Text.ToString()+ @"</text>" +
    @"<text id=""2"">" + TextBoxSubTitle.Text.ToString() + @"</text>" +
    @"<text id=""3"">/Page2.xaml?NavigatedFrom=Toast Notification</text>" +
    @"</binding></visual></toast>";

请参阅以下文档:https://azure.microsoft.com/en-us/documentation/articles/notification-hubs-templates/