How to enable compressed binary messaging in SignalR with Blazor WebAssembly...
Hello, fabulous Syncfusion, Blazor & SignalR gurus!
I aim to add (hopefully compressed) binary messaging between my ASP.NET Core server with SignalR and my Blazor WebAssembly.
Messaging is fully operational in both directions but I notice in the browser's network monitor that the websocket used by SignalR still sends its messages via JSON and Base64. Not only is my stream not compressed as configured server-side but Base64 throws away 2 bits out of 8 yielding a pipe efficiency decrease of around 28%.
It is my understanding that the 'MessagePack' protocol be used to enable full binary communication (removing the usage of JSON / Base64) and I have been following the relevant article at https://learn.microsoft.com/en-us/aspnet/core/signalr/messagepackhubprotocol
As recommended in the above instructions, here is my current code in my server-side WebApplication builder:
builder.Services.AddSignalR()
.AddMessagePackProtocol(options => {
options.SerializerOptions = MessagePackSerializerOptions.Standard
.WithResolver(MessagePack.Resolvers.StandardResolver.Instance)
.WithSecurity(MessagePackSecurity.UntrustedData)
WithCompression(MessagePackCompression.Lz4Block)
WithCompressionMinLength(256);
});
.AddMessagePackProtocol(options => {
options.SerializerOptions = MessagePackSerializerOptions.Standard
.WithResolver(MessagePack.Resolvers.StandardResolver.Instance)
.WithSecurity(MessagePackSecurity.UntrustedData)
WithCompression(MessagePackCompression.Lz4Block)
WithCompressionMinLength(256);
});
However, the same instructions mention to add the following to my '.net client'...
var hubConnection = new HubConnectionBuilder()
.WithUrl("/chathub")
.AddMessagePackProtocol()
.Build();
.WithUrl("/chathub")
.AddMessagePackProtocol()
.Build();
Unfortunately, the sample I've been basing my WebAssembly work on has no concept of a HubConnectionBuilder object and creates its builder as follows:
var builder = WebAssemblyHostBuilder.CreateDefault(args);
Trying everything I could think of, I cannot find a way to find a sub-object of 'WebAssemblyHostBuilder' where I could call the 'AddMessagePackProtocol()' so that MessagePack also works client-side
My hunch is that the server side is properly configured for (compressed) MessagePack but the web-assembly client is not, so I still get JSON + Base64 messaging. (I can live without compression support within MessagePack but would like to lose the 28% pipe efficiency drop caused by JSON + Base64)
Key questions:
Q1: Is MessagePack supported in Blazor WebAssemblies?
Q2: What is the proper procedure to configure the SignalR pipe within Blazor WASM to use MessagePack?
Q3: Is MessagePack the highest-performance pipe for my client/server architecture?
Thank you very much for any hint you can offer!
Jean-Pierre
SIGN IN To post a reply.
2 Replies
JP
Jean-Pierre Poulin
December 16, 2023 01:17 AM UTC
In case anyone runs into this issue it has been solved here at https://stackoverflow.com/questions/77669089/how-to-enable-compressed-binary-messaging-in-signalr-with-blazor-webassembly-wit/77669498#77669498
MK
Muthukrishnan Kandasamy
Syncfusion Team
December 18, 2023 09:23 AM UTC
Hi Jean,
It's great to hear that you've resolved the issue you encountered, as indicated by your post on Stack Overflow.
For reference, here's the link to the solution you found:
Should you have any further questions regarding Syncfusion Blazor components, please feel free to reach out.
Best regards,
Muthukrishnan K
SIGN IN To post a reply.
- 2 Replies
- 2 Participants
-
JP Jean-Pierre Poulin
- Dec 15, 2023 09:54 PM UTC
- Dec 18, 2023 09:23 AM UTC