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.
I have been trying to use Microsoft.Azure.Webjobs.Extensions.NotificationHub. It doesn't seem to be working with Webjob SDK 3 so I've been using SDK 2 instead..
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
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 ?