Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/287.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/azure/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 有没有一种方法可以通过带有Webjob SDK的NotificationHub发送推送通知?_C#_Azure_Azure Webjobs_Azure Webjobssdk - Fatal编程技术网

C# 有没有一种方法可以通过带有Webjob SDK的NotificationHub发送推送通知?

C# 有没有一种方法可以通过带有Webjob SDK的NotificationHub发送推送通知?,c#,azure,azure-webjobs,azure-webjobssdk,C#,Azure,Azure Webjobs,Azure Webjobssdk,我对使用Webjob SDK相当陌生,我正尝试使用带有SDK 3的Webjob将通知推送到NotificationHub 我一直在尝试使用Microsoft.Azure.Webjobs.Extensions.NotificationHub。它似乎不适用于Webjob SDK 3,因此我一直在使用SDK 2 Program.cs using System; using System.Collections.Generic; using System.Linq; using System.Text;

我对使用Webjob SDK相当陌生,我正尝试使用带有SDK 3的Webjob将通知推送到NotificationHub

我一直在尝试使用Microsoft.Azure.Webjobs.Extensions.NotificationHub。它似乎不适用于Webjob SDK 3,因此我一直在使用SDK 2

Program.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实现这一点

System.InvalidOperationException:异常绑定参数“通知”

更新Azure函数和Web作业工具的版本并重新启动

还有没有一种方法可以用SDK 3实现这一点

简而言之,

仅支持
1.x
,而支持
.NETStandard 2.0


有关代码,您可以参考此信息。

您好,谢谢您的回答。我设法用SDK 2实现了这一点,但现在我希望在NotificationHub的同一个函数中发送多个通知。这篇文章稍微谈了一下,但没有进一步讨论这一点。你有什么见解或解决方案吗?