Posts Tagged POCO serialization

Silverlight shared class libraries


I’ve been struggling with the fact that my application really needs shared class libaries and it needs to pass instances of these back and forth with a WCF service running on the back end.  After lots of playing around with data contracts I finally have an elegant solution that uses POCO object serialization and transfers the entities using byte arrays.  The real problem now is the huge size of those serialized objects, wow, DataContractSerializer is wordy as hell – so I’ve stuck a ZIP in the code to reduce the data transmission size but now I’m really on the lookout for a Silverlight serializer that knows what it’s doing via reflection and doesn’t feel the need to write massive descriptor strings on every property – just uses a dictionary of knowntypes and tokens to reduce the size.

If I can’t actually find one of those yet it looks like I may be rolling my sleeves up!  You can find an article here that does an implementation where you write a lot of the serialization logic yourself – that’s going to work for a lot of people but in my app there are so many objects being serialized written by different users it’s too risky to introduce all of the additional coding. My biggest hope is for this project that looks like it might be the right way to go.

Back to the original point: the trick to an elegant, scalable and pluggable implementation of POCO serialization between Silverlight and WCF is to use MEF or write your own type scanner and decorate the types you want to send with an attribute that indicates the type needs to be added to the KnownTypes collection of the serializer.  The built in KnownType attribute only works when you know all of the classes you might want to serialize in advance – not good in the case of a dynamic application, because every time someone wrote a new class you would have to change the WCF definition!

//UPDATE:

Oh well, tried out the serialization library that looked good, unfortunately I need to have my properties serialized not fields, and the project clearly has had that disabled for a reason  – quite a lot of hard to trace errors when I did enable it so I guess it’s back to the drawing board.  Damn.

//FURTHER UPDATE: Another post on this blog lists my solution to this.

, , , , ,

Leave a comment