question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Support BSON in SignalR Core

See original GitHub issue

I know about MessagePack but my scenario involves Asp.Net Core receiving raw BSON from MongoDB, and then forwarding it onward to a .NET client app. I don’t want to needlessly translate the data from one binary format (BSON) to another (MessagePack).

Is sending BSON over SignalR Core currently achievable? If so then how and how involved? Otherwise, please consider adding BSON support, or enabling any binary format. I know MessagePack is better and all, but Mongo uses BSON and I use Mongo.

The alternative that comes to mind is to use web APIs since HTTP handles any binary format, and Asp.Net Core lets me configure output formatters. What about configuring formatters in SignalR Core? I couldn’t find any Formatters options. I want to stick to using SignalR Core rather than web API, due to other benefits of the former.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:10 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
analogrelaycommented, May 2, 2019

@highfield makes a good point. There’s no reason you couldn’t just send the BSON “via MessagePack” as a byte array, using a model like this:

public class MongoResult
{
    public byte[] RawBson { get; set; }
}

If you send this object through SignalR, it will be appropriately serialized and deserialized and on the client you can access .RawBson and pass it to Mongo’s deserializer.

You won’t be “converting” the BSON to SignalR’s format, you’re just wrapping it in a SignalR message. In JSON, we’ll base-64 encode it for you automatically, in MessagePack we’ll send it as mostly raw binary (with a little bit of protocol goop wrapping it).

0reactions
highfieldcommented, May 2, 2019

Also, MongoDB’s .NET library makes it easy to deserialize only the pieces of BSON that are needed. That means the server-side code can see the parts it needs, and compose them with other parts, without deserializing everything.

@ChainReactive that’s not part of the protocol, rather of the interface exposed by the driver. Moreover, you’re asking to support BSON-over-websocket: to me that means the binary representation of the original data, not the DOM useful for manipulation.

That being said, why not make yourself a small test? take any BSON recordset coming out the DB, then copy its binary buffer to a signalR response. On the client side, you should able to deserialize th stream by the MongoDB official library. I’d first make an attempt using a “verbose” way using a base-64 codec over the text signalR: overhauled, but pretty easy as starting point. If successful, you might switch the MessagePack in order to transfer the binary as is.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Support BSON in SignalR Core · Issue #9819
NET client app. I don't want to needlessly translate the data from one binary format (BSON) to another (MessagePack). Is sending BSON over ......
Read more >
ASP.NET Core SignalR configuration
ASP.NET Core SignalR supports two protocols for encoding messages: JSON and MessagePack. Each protocol has serialization configuration ...
Read more >
BSON (Binary JSON) and how your Web API can be even ...
NET already has great BSON support, it is actually quite easy. Now, you might be asking a question, why to do it in...
Read more >
SignalR - can't connect from js client to asp.net core 7 server
I have built asp.net core 7 project based on GRPC template because i need to have grpc communication in my service.
Read more >
Real-time in Sitecore using SignalR and MongoDB
Real-time in Sitecore using SignalR and MongoDB · 1. Setup SignalR and make it work with Sitecore · 2. Create a real-time connection...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found