Azure / azure-notificationhubs-dotnet

.NET SDK for Azure Notification Hubs
MIT License
70 stars 119 forks source link

[BUG] Send Template Notification Fails (WNS) #266

Open josuuribe opened 1 year ago

josuuribe commented 1 year ago

Describe the bug Using WNS template for send a notification produces outcome "The Notification payload is invalid"

Exception or Stack Trace The outcome result is "The Notification payload is invalid"

To Reproduce

Code Snippet

static void Main(string[] args)
{
var connectionString = "Place your connection here";
var notificationHubClient = NotificationHubClient.CreateClientFromConnectionString(connectionString, "your notification hub", true);
Installation installation = new Installation();
installation.InstallationId = Guid.NewGuid().ToString();
installation.PushChannel = "Place your channel here";
installation.Platform = NotificationPlatform.Wns;

var template = new InstallationTemplate();
template.Body = @"<toast><visual><binding><text>Test +{$(object)}</text></binding></visual></toast>"; // Use any example
template.Headers = new Dictionary<string, string>() { { "X-WNS-Type", "wns/toast" } };
installation.Templates = new Dictionary<string, InstallationTemplate>
                       {
                            {
                                "WindowsToast",
                                 template 
                            }
                        };
notificationHubClient.CreateOrUpdateInstallationAsync(installation);

var props = new Dictionary<string, string> {
{ "object", "Any string" } };
var n = new TemplateNotification(props);
n.Headers.Add("X-WNS-Type", "wns/toast");
var outcome = notificationHubClient.SendNotificationAsync(n).GetAwaiter().GetResult();

Expected behavior Receive notification.

Screenshots N/A

Setup (please complete the following information):

Additional context I am creating a MAUI application, but this also fails with console, if instead of using SendNotificationAsync I try with SendWindowsNativeNotificationAsync it works fine.