我有一个C#/UWP应用程序,它接收来自WNS的通知,我可以使用测试页面向它发送原始通知。唯一的问题是,当发送模板通知时,我无法将设备注册到集线器以接收原始通知。这是基本代码:
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/原始模板”选项,但是我找不到关于如何注册一个的文档。如果这重要的话,原始数据的实际格式是JSON。
修正了戴夫·斯密茨帮助下的代码:
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);发布于 2017-02-02 00:44:59
我想之前有过这个。您需要添加一些标头;这应该会有所帮助:
WnsHeaderCollection wnsHeaderCollection = new WnsHeaderCollection();
wnsHeaderCollection.Add("X-WNS-Type", @"wns/raw");
WindowsTemplateRegistrationDescription registrationDescription = new WindowsTemplateRegistrationDescription("<channel uri", "<template payload>", wnsHeaderCollection, tags);
notificationHubClient.CreateRegistrationAsync(registrationDescription);https://stackoverflow.com/questions/41992242
复制相似问题