【发布时间】:2022-11-15 15:07:49
【问题描述】:
我使用 Azure Functions 创建了 Azure SignalR Serverless 服务。 我的客户端是一个 .NET 6 WPF 应用程序。
协商功能按预期工作,连接成功建立。
CosmosDBTrigger、HttpTrigger 和 TimerTrigger 函数也可以按预期工作。
但是,SignalRTrigger 不起作用,我不知道为什么。
SignalRTrigger 函数:
[FunctionName("SignalRTest")]
public async Task SignalRTest([SignalRTrigger("myHub", "messages", "SignalRTest")] InvocationContext invocationContext, string message, ILogger logger)
{
logger.LogInformation($"Receive {message} from {invocationContext.ConnectionId}.");
await Clients.All.SendAsync("signalRTestMessage", message);
}
客户端配置:
connection = new HubConnectionBuilder()
.WithUrl("https://<SiteURL>.azurewebsites.net/api")
.Build();
await connection.StartAsync().ContinueWith(async (e) =>
{
try
{
await connection.InvokeAsync("SignalRTest", "TestMessage");
}
catch (Exception ex)
{
Debug.WriteLine(ex.Message);
}
});
异常总是返回错误信息:
调用失败,状态码 404
我已经使用 Azure Functions 中生成的
signalr_extension密钥配置了 SignalR 上游。我已经关注了Microsoft docs 上的官方文档,但仍然无法解决问题。
【问题讨论】:
标签: c# wpf azure-functions .net-6.0 azure-signalr