SignalRCore和Azure功能 [英] SignalRCore and Azure functions

查看:182
本文介绍了SignalRCore和Azure功能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Asp.Net-Core 3.0 Web服务,它作为一个单一容器功能应用程序运行.这对我的Rest api非常有效.

I got an Asp.Net-Core 3.0 webservice that I run as a Single Container Function App. This is working great for my Rest api.

但是我最近添加了SignalR集线器来添加通知服务,但这在Azure功能中的Web应用程序的托管版本中不起作用.当我尝试使用.Net SignalRCore 3客户端连接到集线器时,出现以下错误:

But I recently added a SignalR hub to add a notification service but this doesn't work in the hosted version of my web-app in Azure functions. When I try to connect to the hub using a .Net SignalRCore 3 client I get the following error:

在握手开始之前,服务器已断开连接.

The server disconnected before the handshake could be started.

当我将容器作为基本Azure容器实例运行时,SignalR功能运行良好.

When I run the container as a basic Azure container instance the SignalR functionality is working fine.

有什么想法为什么会发生,以及是否甚至可以将SignalR集线器添加到azure函数托管的Docker容器中?

Any ideas why this is happening and if it is even possible to add a SignalR hub to a azure function hosted docker container?

推荐答案

SignalR似乎不适用于功能性应用程序中托管的Asp.Net-Core3 Docker容器实例,因为功能性应用程序应该是无状态的而SignalR不是.为此,您将需要使用来自AspNetCore Web服务的单独的Azure SignalR服务.

It seems like that SignalR doesn't work in Asp.Net-Core3 Docker Container Instances hosted in Function Apps by design, because function apps are supposed to be stateless and SignalR isn't. For this you will need to use the seperate Azure SignalR service from your AspNetCore webservice.

https://azure.microsoft.com/en-us/服务/信号服务/

并在您的StartUp类中更改注册代码.

And change the registration code in your StartUp class.

var signalRServerBuilder = services.AddSignalR();

var signalRConnectionString = m_configuration[@"SignalRConnectionString"];
if (!string.IsNullOrWhiteSpace(signalRConnectionString))
{
    signalRServerBuilder.AddAzureSignalR(signalRConnectionString);
}

这篇关于SignalRCore和Azure功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆