Changing the serialization protocol
By default, SignalR serializes messages with JSON. Using the Microsoft.AspNetCore.SignalR.Protocols.MessagePack
NuGet package, a binary serialization format can be used instead. This is an optimization that reduces the data that’s sent.
To support this, all we need to do is update the DI configuration in the service, after adding the NuGet package:
Codebreaker.Live/ApplicationServices.cs
public static void AddApplicationServices(this IHostApplicationBuilder builder) { builder.Services.AddSignalR() .AddMessagePackProtocol(); } // code removed for brevity
The AddMessagePackProtocol
method adds MessagePack
as another option for serialization. JSON is still available.
Regarding the client, the same NuGet package is required, but this time with the following configuration:
LiveTestClient/LiveClient.cs
string liveUrl = options.Value.LiveUrl ?? throw new InvalidOperationException("LiveUrl...