[英]Is there a way to send Push Notification through a NotificationHub with the Webjob SDK?
I'm fairly new to using the Webjob SDK and I am trying to push notifications to a NotificationHub with a Webjob with SDK 3. 我是使用Webjob SDK的新手,我正在尝试使用带有SDK 3的Webjob将通知推送到NotificationHub。
I have been trying to use Microsoft.Azure.Webjobs.Extensions.NotificationHub. 我一直在尝试使用Microsoft.Azure.Webjobs.Extensions.NotificationHub。 It doesn't seem to be working with Webjob SDK 3 so I've been using SDK 2 instead.. 它似乎不适用于Webjob SDK 3,所以我一直在使用SDK 2。
Programme.cs Programme.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.Azure.WebJobs;
namespace WJNotificationHub
{
class Program
{
static void Main()
{
var config = new JobHostConfiguration();
if (config.IsDevelopment)
{
config.UseDevelopmentSettings();
}
config.UseNotificationHubs();
var host = new JobHost(config);
host.RunAndBlock();
}
}
}
Functions.cs Functions.cs
using System.IO;
using Microsoft.Azure.NotificationHubs;
using Microsoft.Azure.WebJobs;
using Newtonsoft.Json;
namespace WJNotificationHub
{
public class Functions
{
public static void ProcessQueueMessage([QueueTrigger("queue")] string message, TextWriter log, [NotificationHub] out Notification notification)
{
log.WriteLine(message);
notification = new GcmNotification(message.ToGcmPayload());
}
}
public static class PlatformNotificationsExtensions
{
public static string ToGcmPayload(this string message)
{
var gcmPayloadModel = new
{
data = new
{
message = message
}
};
return JsonConvert.SerializeObject(gcmPayloadModel);
}
}
}
With this code I have the following exception : 使用此代码,我有以下例外:
Exception while executing function: Functions.ProcessQueueMessage
Microsoft.Azure.WebJobs.Host.FunctionInvocationException : Exception while executing function: Functions.ProcessQueueMessage ---> System.InvalidOperationException : Exception binding parameter 'notification' ---> System.NullReferenceException : La référence d'objet n'est pas définie à une instance d'un objet.
Also is there a way to do it with SDK 3 ? 还有办法用SDK 3吗?
System.InvalidOperationException : Exception binding parameter 'notification' System.InvalidOperationException:异常绑定参数'notification'
Update the Azure Function and Web Jobs Tools
version and restart it. 更新Azure Function and Web Jobs Tools
版本并重新启动它。
Also is there a way to do it with SDK 3 ? 还有办法用SDK 3吗?
In short No . 总之没有 。
The Notification Hub only support 1.x
while Webjob SDK 3 support .NETStandard 2.0
. Notification Hub仅支持1.x
而Webjob SDK 3支持.NETStandard 2.0
。
For the code, you could refer to this article . 对于代码,您可以参考这篇文章 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.