I use RestSharp and use Json.NET for serialization (see here ).
Json.NET supports BSON, and since some of my requests have huge blocks of binary data, I think this will speed up my application significantly. However, as far as I can tell, RestSharp does not have native BSON support.
Using Json.NET is implemented as a custom serializer for RestSharp, and so at first glance it seems that you can use this custom serializer to use BSON. But the Serialize method of the RestSharp.Serializers.ISerializer interface returns a string - which (I suppose) is not suitable for BSON. So, I assume that to make changes to RestSharp more significant changes will be required.
Has anyone figured out how to do this?
Update: I looked at the source of RestSharp and found that the RestRequest.AddBody method, which takes my object and serializes it into the request body, ultimately calls Request.AddParameter (with the serialized object data and the RequestBody parameter RequestBody ).
I thought that I could serialize my object to BSON and then directly call Request.AddParameter - and really can. However, when RestSharp executes RestRequest , it cannot put binary content in the request because there are other built-in assumptions that the contents of the request are UTF-8 encoded.
Thus, it seems that this hack will not work - you will need to make some changes to RestSharp itself, and I'm not the person for this job ...
Update 2: I decided to try using a debugger to find out how much of RestSharp I would have to change to overcome the body encoding problem, so I changed my version of RestSharp to NuGet and included the RestSharp project in my solution. And ... he worked .
It turned out that over the past few months there has been a change in RestSharp, which is not yet in the NuGet version.
So now you can use AddParameter and transfer it to an already-BSON-encoded object, and RestSharp will send it to the server without complaint.
Gary mcgill
source share