Reputation: 295
I want to be able to query my database over the web, and I am wanting to use a WCF service to handle the requests and results. The problem is that due to the amount of data that can potentially be returned from these queries, I'm worried about how these results will be serialised over the network. For example, I can imagine the XML serialisation looking like:
<Results>
<Person Name="Adam" DateOfBirth="01/02/1985" />
<Person Name="Bob" DateOfBirth="04/07/1986" />
</Results>
And the binary serialisation containing types names and other (unnecessary) metadata. Perhaps even the type name for each element in a collection? o_o
Ideally, I'd like to perform the serialisation of certain 'DataContract'-s myself so I can make it super-compact. Does anyone know if this is possible, or of any articles which explain how to do custom serialisation with WCF?
Thanks in advance
Upvotes: 2
Views: 3105
Reputation: 755321
WCF support a binary serialization format out of the box - it's used by default in the netTcpBinding
. I would recommend to try and use that for your tests first - only if that doesn't work and doesn't compress enough, and you're confident you can outsmart and outprogram the entire WCF team, go and roll your own custom binary serialization format.
Check out some excellent resources:
With the composability of WCF bindings, you could easily also create a e.g. binary HTTP binding.
The main issue here will be: if you do something like this, both ends of the communication channel must agree on how things are done, e.g. you cannot expect a simple browser to be able to connect and understand your custom binary encoding anymore - you need to be able to control the client and the server side of the wire.
Upvotes: 4