I have a C#/UWP app which receives notifications from WNS, and I can use the Azure Notification Hub test page to send it a raw notification. The only issue is I cannot register the device with the hub to receive the raw notification when a template notification is sent. This is the basic code:
PushNotificationChannel channel = await PushNotificationChannelManager.
CreatePushNotificationChannelForApplicationAsync();
NotificationHub hub = new NotificationHub(NotificationSettings.HubName,
NotificationSettings.HubListenConnectionString);
TemplateRegistration registration = await hub.
RegisterTemplateAsync(channel.Uri, template, "data", tags);
What I'm trying to figure out is what value of template I need to have it just pass the data through as raw. This is the error I get at registration time:
The bodyTemplate is not in accepted XML format. The first node of the bodyTemplate should be Badge/Tile/Toast, except wns/raw template, which need to be an valid XML
By that message apparently there is a "wns/raw template" option but I can find no documentation on how to register one. The actually format of the raw data is JSON if that matters.
Fixed code from the help from Dave Smits:
PushNotificationChannel channel = await PushNotificationChannelManager.
CreatePushNotificationChannelForApplicationAsync();
NotificationHub hub = new NotificationHub(NotificationSettings.HubName,
NotificationSettings.HubListenConnectionString);
WnsHeaderCollection wnsHeaderCollection = new WnsHeaderCollection();
wnsHeaderCollection.Add("X-WNS-Type", @"wns/raw");
TemplateRegistration registration =
new TemplateRegistration(channel.Uri, template, "test",
tags, wnsHeaderCollection);
Registration r = await hub.RegisterAsync(registration);
i thinki had this before. you need to add some headers; this should help:
WnsHeaderCollection wnsHeaderCollection = new WnsHeaderCollection();
wnsHeaderCollection.Add("X-WNS-Type", @"wns/raw");
WindowsTemplateRegistrationDescription registrationDescription = new WindowsTemplateRegistrationDescription("<channel uri", "<template payload>", wnsHeaderCollection, tags);
notificationHubClient.CreateRegistrationAsync(registrationDescription);