【发布时间】:2019-05-10 17:12:16
【问题描述】:
我对使用 Webjob SDK 还很陌生,我正在尝试使用带有 SDK 3 的 Webjob 将通知推送到 NotificationHub。
我一直在尝试使用 Microsoft.Azure.Webjobs.Extensions.NotificationHub。它似乎不适用于 Webjob SDK 3,所以我一直在使用 SDK 2..
程序.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();
}
}
}
函数.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);
}
}
}
使用此代码,我有以下异常:
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.
还有没有办法用 SDK 3 做到这一点?
【问题讨论】:
标签: c# azure azure-webjobs azure-webjobssdk