SignalR – Modify the Max WebSocket Message Size

Introduction

The default buffer size for sending data over WebSockets with SignalR is 64kB (65536 bytes), once exceeded, SignalR will fail to handle incoming data and the hub method will not trigger. The method for increasing the max message size is not obvious and difficult to find, particularly for the .NET Framework version of SignalR.

Solution – ASP .NET Framework

In the Configuration method in the Startup class, the limit can be modified by setting GlobalHost.Configuration.MaxIncomingWebSocketMessageSize to the desired value, or null to remove the limit.

public class Startup 
{    
    public void Configuration(IAppBuilderapp)
    {
        app.MapSignalR();
        GlobalHost.Configuration.MaxIncomingWebSocketMessageSize = null;
    }
}

Solution – ASP .NET Core

In .NET Core, the maximum size can be modified by setting the hub configuration’s MaximumReceiveMessageSize in the ConfigureServices(IServiceCollection services) method. As with .NET Framework, a null value removes the limit.

services.AddSignalR(hubOptions =>{    
    hubOptions.MaximumReceiveMessageSize = null;
});