繁体   English   中英

Azure Notification Hub注册WNS的原始模板

[英]Azure Notification Hub register raw template for WNS

我有一个C#/ UWP应用程序,该应用程序从WNS接收通知,并且我可以使用Azure Notification Hub测试页向其发送原始通知。 唯一的问题是,发送模板通知时,我无法向集线器注册设备以接收原始通知。 这是基本代码:

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

通过该消息,显然有一个“拥有/原始模板”选项,但是我找不到有关如何注册一个的文档。 如果重要的话,原始数据的实际格式为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);

我想我以前有这个。 您需要添加一些标题; 这应该有助于:

WnsHeaderCollection wnsHeaderCollection = new WnsHeaderCollection();
wnsHeaderCollection.Add("X-WNS-Type", @"wns/raw");
WindowsTemplateRegistrationDescription registrationDescription = new WindowsTemplateRegistrationDescription("<channel uri", "<template payload>", wnsHeaderCollection, tags);
notificationHubClient.CreateRegistrationAsync(registrationDescription);

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM