我有一个.Net Core 3.0控制台项目,其中包括WebJob函数,该函数具有到Azure Signal R的输出绑定。该应用程序生成正常,但是当我运行它并尝试通过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。