Search code examples
azuresignalrazure-functionsasp.net-core-signalr

SignalRCore and Azure functions


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.

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.

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

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


Solution

  • 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/services/signalr-service/

    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);
    }