0

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 ?

ikko
  • 3
  • 1

1 Answers1

1

System.InvalidOperationException : Exception binding parameter 'notification'

Update the Azure Function and Web Jobs Tools version and restart it.

Also is there a way to do it with SDK 3 ?

In short No.

The Notification Hub only support 1.x while Webjob SDK 3 support .NETStandard 2.0. enter image description here

For the code, you could refer to this article.

Joey Cai
  • 18,968
  • 1
  • 20
  • 30
  • Hello, thank you for your answer. I managed to do it with SDK 2 but now I am looking to send multiple notifications in the same function on a NotificationHub. The article talks about it a bit but does not go further on this point. Do you have any insight or solution ? – ikko May 10 '19 at 10:49