简体   繁体   English

有没有办法通过带有Webjob SDK的NotificationHub发送推送通知?

[英]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.xWebjob SDK 3支持.NETStandard 2.0 在此输入图像描述

For the code, you could refer to this article . 对于代码,您可以参考这篇文章

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 有没有办法使用Webjob SDK向NotificationHub发送多个通知? - Is there a way to send multiple notification to a NotificationHub with Webjob SDK? NotificationHub在注册标签UWP中发送通知 - NotificationHub send notification in registered tag UWP 我可以通过 NotificationHub Azure 中的 registrationId 发送通知吗? - I can send notification by registrationId in NotificationHub Azure? 如何通过 GCM 向超过 1000 个用户发送推送通知 - How to send push notification to more then 1000 user through GCM 发送广播推送通知 - Send broadcast Push Notification 有没有一种方法可以将推送通知从Web门户发送到Google Cloud Messaging? - Is there a way to send push notification from a web portal to Google Cloud Messaging? 无法使用Azure.NotificationHubs SDK发送Windows Phone推送通知 - Unable to send Windows Phone push notification using Azure.NotificationHubs SDK 通过Cortana发送推送通知 - Send push notification via Cortana 如何使用C#通过APNS将推送通知发送到iOS? - How can I send push notification to iOS through APNS using C#? Azure Notificationhub-PN发送在沙盒中工作,但不在生产中 - Azure Notificationhub - PN send working in sandbox but not in production
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM