Mike Talbot's Blog
Posts Tagged WCF Silverlight
Silverlight shared class libraries
Posted by whydoidoit in Uncategorized on February 13, 2010
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.
DataContractSerializer, MEF, POCO serialization, shared class libararies, Silverlight, WCF Silverlight
Welcome!
All code on this blog is open source. You are free to use all of the code on this blog for any purpose, but it all comes without any warranty whatsoever. You must not use any code on this blog to infringe any patent and I can offer no warranty that the presence of code here implies that it is not patented for some purpose by the author or another party. No code posted by the author has been patented for the basic application demonstrated.
The posts on this blog come as a result of a business application I developed for Silverlight and a game I am writing in Unity. I've tried to write posts that reflect things I've searched for and not been able to find elsewhere.
I decided to publish this work as a quid pro quo for all of the hugely useful articles and examples I've learned from and incorporated.
I'm also really glad to get bug reports - this code is being used professionally by me and I need to keep it bug free :)
I'd appreciate a comment or a rating if you decide to go ahead and use anything, feel free to ask questions or make suggestions for improvements!
Best
Mike
Search
Top Rated
- AllChildren ArrangeOverride Automatic Grid Binary Binary Serializer Bug C# ComboBox Component Control custom panel custom silverlight panel dashboard dashboard layout DataBinding DataContract DataContractSerializer DropShadows Element is already the child of another element Element is already the child of another element silverlight Elements is already the child of another element Extensible Application Markup Language Flip Flip Control FrameworkElement visible Grid Grid layout gui ItemsSource Jonathan Feinberg LoadComponent MeasureOverride MEF Microsoft Silverlight Page Turn Plane Projection POCO serialization Programming proportional panel ProportionalPanel Reflection selection lost on ItemsSource update Serialization shared class libararies Share silverlight class .NET Silverlight Silverlight actually visible Silverlight all children Silverlight Binary Serialization Silverlight Binary Serializer Silverlight flip control Silverlight Serialization Source code Stack Overflow Tag cloud TFS UI Performance unity Unity Serializer Visible visual parent VisualState VisualStateManager VisualState Trigger Visual Tree VisualTree WCF Silverlight Word Cloud Wordle XAML XAML debugging XAML Error XamlReader XML [Line: 0 Position: 0]
Author
Mike Talbot is Chief Visionary of 3radical. He started his career as a game programmer working for UbiSoft and Electronic Arts among others. Currently he is programming mobile applications in Javascript, HTML5 and ASP.NET. email: mike.talbot@3radical.com
twitter: mike_talbot
WinApse Latest
- Replatforming Guide: Pros, Cons, and Impact
- Cypress vs Selenium: Why Cypress is Better!
- In-Depth Review: Apache Spark and Flink Side by Side
- C# Null Coalescing Best Practices
- COPY vs ADD in Docker: A Detailed Comparison
- JSON Web Key Sets (JWKS) Ultimate Guide
- What is a Technical Debt Register Template?
- What is Event-Driven Programming?
- Mailtrap Service Review: Pros and Cons
- PUT vs PATCH with REST APIs
Silverlight Show News
- An error has occurred; the feed is probably down. Try again later.