Support BSON in SignalR Core
See original GitHub issueI 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:
- Created 4 years ago
- Comments:10 (5 by maintainers)

Top Related StackOverflow Question
@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:
If you send this object through SignalR, it will be appropriately serialized and deserialized and on the client you can access
.RawBsonand 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).
@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.