首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Azure通知中心注册WNS的原始模板

Azure通知中心注册WNS的原始模板
EN

Stack Overflow用户
提问于 2017-02-02 00:17:02
回答 1查看 572关注 0票数 1

我有一个C#/UWP应用程序,它接收来自WNS的通知,我可以使用测试页面向它发送原始通知。唯一的问题是,当发送模板通知时,我无法将设备注册到集线器以接收原始通知。这是基本代码:

代码语言:javascript
复制
PushNotificationChannel channel = await PushNotificationChannelManager.
  CreatePushNotificationChannelForApplicationAsync();
NotificationHub hub = new NotificationHub(NotificationSettings.HubName,
  NotificationSettings.HubListenConnectionString);
TemplateRegistration registration = await hub.
  RegisterTemplateAsync(channel.Uri, template, "data", tags);

我试图找出模板的值,我需要它将数据作为原始数据传递。这是我在注册时遇到的错误:

代码语言:javascript
复制
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。

修正了戴夫·斯密茨帮助下的代码:

代码语言:javascript
复制
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);
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2017-02-02 00:44:59

我想之前有过这个。您需要添加一些标头;这应该会有所帮助:

代码语言:javascript
复制
WnsHeaderCollection wnsHeaderCollection = new WnsHeaderCollection();
wnsHeaderCollection.Add("X-WNS-Type", @"wns/raw");
WindowsTemplateRegistrationDescription registrationDescription = new WindowsTemplateRegistrationDescription("<channel uri", "<template payload>", wnsHeaderCollection, tags);
notificationHubClient.CreateRegistrationAsync(registrationDescription);
票数 5
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/41992242

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档