我有一个从 WNS 接收通知的 C#/UWP 应用程序,我可以使用 Azure 通知中心测试页面向它发送原始通知。唯一的问题是我无法在集线器上注册设备以在发送模板通知时接收原始通知。这是基本代码:
PushNotificationChannel channel = await PushNotificationChannelManager.
CreatePushNotificationChannelForApplicationAsync();
NotificationHub hub = new NotificationHub(NotificationSettings.HubName,
NotificationSettings.HubListenConnectionString);
TemplateRegistration registration = await hub.
RegisterTemplateAsync(channel.Uri, template, "data", tags);
我想弄清楚的是模板的价值,我需要它只是将数据作为原始数据传递。这是我在注册时遇到的错误:
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
通过该消息,显然有一个“wns/raw 模板”选项,但我找不到有关如何注册的文档。如果重要的话,原始数据的实际格式是 JSON。
在 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);