Reputation: 2396
I'm using WCF to return a list of complex objects returned from SQL Server with Linq.
I want to return a list of objects with around 16 properties and 2 References to other complex types (with around 8 properties each one).
I've seen in fiddler that each object returned (when serialized to XML) is around 5KB and, when I try to return a full list (900 items) it's around 3MB!!!
Is this normal? Is there any other way to serialize data to a light-weight format?
Thanks in advance!!
Upvotes: 2
Views: 206
Reputation:
XML is very verbose, and that size does not really surprise me (taking the size of your list into consideration - 900 items is too much, if you ask me).
If you need to "pack" your data, i'd recommend serializing your objects to JSON, since that removes a lot of verbosity. There is a built-in JSON Serialization mechanism, so you should be able to get started really fast. The only thing i had problems with, were the DateTime fields, which sometimes error'd with the built-in JSON Serializer, but there are workarounds to that.
However that will also mean some work would have to be done on both ends. Serverside, you need to transform your entities to some kind of transport entities, or DTOs, if you will. On client side, you cant work with those right away, but need to deserialize the data first, and re-built your datamodel from there.
You'd want to pack in a "DTO Info" in your sent object, so your client knows what to expect of the packets it is receiving. Like, which type has been serialized, and so on.
Upvotes: 3
Reputation: 27085
Look into NetTcpBinding if this is possible for you, this will reduce network traffic very much compared to XML Serialization
Upvotes: 4