views:

352

answers:

2

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

+1  A: 

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.

marc_s
A: 

Thanks for that. For the record, it's not a matter of outprogramming the WCF team, I just know from experience that .NET binary serialisation is quite bulky so it can be automatically handled with reflection. For example, serialising type names.

I figured that serialising a List, as per my example above would also need to serialise the type name for all of the elements in the list. I might be wrong, but it's the only way I can see it working with, for example, classes that may derive from Person. In my situation, I know exactly what needs to be serialised, and that Person is sealed. With all this information, I'm better placed to serialise the list myself for compact-ness which is essential in my current project.

I shall read through the links. I'll test the default binary serialisation to confirm the above.

Thanks again.

Barguast
Don't confuse .NET Runtime Serialization with the BinaryFormatter with the DataContractSerializer writing binary output. The two are entirely different, with the DataContractSerializer serializing the XML Infoset into binary format.
John Saunders
See the third link I sent you - the guy comparing the WCF binary serialization vs. the .NET binary formatter is quite impressed with the WCF's binary serialization performance and capabilities - *much* better than straight .NET binary formatter, he says...
marc_s