gpt4 book ai didi

c# - Azure 通知中心为 WNS 注册原始模板

转载 作者:太空宇宙 更新时间:2023-11-03 21:04:43 24 4
gpt4 key购买 nike

我有一个从 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);

我想弄清楚的是我需要的模板的值(value)是什么,它只是将数据作为原始数据传递。这是我在注册时遇到的错误:

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 template”选项,但我找不到关于如何注册一个的文档。如果重要的话,原始数据的实际格式是 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);

关于c# - Azure 通知中心为 WNS 注册原始模板,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41992242/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com