.net-core-3.0 - WebJob .Net Core 3 的 Azure SignalR 绑定(bind)不起作用

标签 .net-core-3.0 asp.net-core-signalr azure-signalr

我有一个 .Net Core 3.0 控制台项目,其中包含 WebJob 函数,该函数具有与 Azure Signal R 的输出绑定(bind)。该应用程序构建正常,但是当我运行它并尝试通过 SignalR 发送消息时,出现以下错误:

{System.MissingMethodException: Method not found: 'System.String Microsoft.Azure.SignalR.AuthenticationHelper.GenerateAccessToken(System.String, System.String, System.Collections.Generic.IEnumerable`1<System.Security.Claims.Claim>, System.TimeSpan, System.String)'.
at Microsoft.Azure.SignalR.Management.RestApiAccessTokenGenerator.Generate(String audience, Nullable`1 lifetime)
at Microsoft.Azure.SignalR.Management.RestApiProvider.GenerateRestApiEndpoint(String path, Nullable`1 lifetime)
at Microsoft.Azure.SignalR.Management.RestApiProvider.GetSendToGroupEndpoint(String groupName, Nullable`1 lifetime)
at Microsoft.Azure.SignalR.Management.RestHubLifetimeManager.SendGroupAsync(String groupName, String methodName, Object[] args, CancellationToken cancellationToken)
at Microsoft.AspNetCore.SignalR.Internal.GroupProxy`1.SendCoreAsync(String method, Object[] args, CancellationToken cancellationToken)
at Microsoft.Azure.WebJobs.Extensions.SignalRService.AzureSignalRClient.SendToGroup(String groupName, SignalRData data)
at Microsoft.Azure.WebJobs.Extensions.SignalRService.SignalRAsyncCollector`1.AddAsync(T item, CancellationToken cancellationToken)
at InSysWebJobP300DataProcessor.Helper.ProcessMinuteData(Message message, ConnectionMultiplexer redisConnection, IAsyncCollector`1 signalRMessages, ILogger log) in E:\InergySystems\GitHub\InSysCore\InSysWebJobP300DataProcessor\Helper.cs:line 125}

SignalR 服务在 Program.Main 中注册:

static void Main(string[] args)
{
    var builder = new HostBuilder();
    builder.ConfigureWebJobs(b =>
    {
        b.AddAzureStorageCoreServices();
        b.AddServiceBus().AddSignalR();
    });
    builder.ConfigureLogging((context, b) =>
    {
        b.ClearProviders();
        b.AddConfiguration(context.Configuration.GetSection("Logging"));
        if (context.HostingEnvironment.IsDevelopment())
        {
            b.AddConsole();
        }
    });

    var host = builder.Build();
    using (host)
    {
        host.Run();
    }
}

我有一个具有以下签名的函数:

[FunctionName("ProcessMinuteData")]
public async Task RunAsync([ServiceBusTrigger("data", Connection = "AzureWebJobsServiceBusConnection")]Message message, [SignalR(HubName = "insyshub")] IAsyncCollector<SignalRMessage> signalRMessages, ILogger log)

从服务总线接收到的消息处理得很好,但是尝试使用以下命令通过 SignalR 推送消息会导致上述错误:

await signalRMessages.AddAsync(new SignalRMessage
{
    GroupName = "GroupName",
    Target = "targetMethod",
    Arguments = new[] { JsonConvert.SerializeObject(message) }
});

请注意,该应用不需要通过 SignalR 接收消息,只需将它们推送出去即可。

我安装了以下 NuGet 包:

<PackageReference Include="Microsoft.AspNetCore.SignalR" Version="1.1.0" />
<PackageReference Include="Microsoft.Azure.SignalR" Version="1.2.1" />
<PackageReference Include="Microsoft.Azure.WebJobs" Version="3.0.14" />
<PackageReference Include="Microsoft.Azure.WebJobs.Extensions" Version="3.0.5" />
<PackageReference Include="Microsoft.Azure.WebJobs.Extensions.Http" Version="3.0.2" />
<PackageReference Include="Microsoft.Azure.WebJobs.Extensions.ServiceBus" Version="4.0.0" />
<PackageReference Include="Microsoft.Azure.WebJobs.Extensions.SignalRService" Version="1.0.2" />
<PackageReference Include="Microsoft.Azure.WebJobs.Extensions.Storage" Version="3.0.10" />
<PackageReference Include="Microsoft.Azure.WebJobs.Logging.ApplicationInsights" Version="3.0.14" />
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="3.0.1" />

最佳答案

似乎从 Microsoft.Azure.SignalR 1.2.0 开始,如果您想使用我在问题中详细说明的方法,您现在需要包含 Microsoft.Azure.SignalR.Management。

在 1.2.0 之前,您不需要包含 Microsoft.Azure.SignalR.Management。

关于.net-core-3.0 - WebJob .Net Core 3 的 Azure SignalR 绑定(bind)不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58965003/

相关文章:

asp.net-core - ASP.NET Core 3.0 未在 Visual Studio 2019 上显示

asp.net-core - 在 Blazor 组件中获取当前用户

c# - SignalR dotnet 核心认证

c# - 从另一个对象中获取 SignalR Core 中的 Hub 上下文

azure - 为什么在部署 Blazor 服务器端应用程序时建议使用 Azure SignalR 服务?

Azure SignalR 服务实现 .NET 6 Azure Function 隔离进程

json - .Net Core 3 和 EF Core 3 包含问题 (JsonException)

asp.net - 如何从 Hub 外部将 SignalR 连接添加到 Hub 组?

.net - 控制台应用程序如何连接到 Azure SignalR 服务器以从我的 Web API 获取通知

c# - .Net Core 3.0 中的请求正文为空