SOA - Server to Silverlight and Back

by Bobbi Perreault 1. August 2008 10:52
Share on Facebook

The problem is how to transport objects and data from server to silverlight and back and do the least amount of typing. The databinding features of a Silverlight application make transporting the contents of an object from code to UI so simple. That's how I want to be able to send the contents of the object to the server and how I want to be able to retrieve the contents of that object on the server side.


In a monolithic web application this is simple, serialize from object to xml and back again into object after the outside code has been executed against the object contents.
In a silverlight project, it's not so simple for these reasons:

  • 1. Silverlight doesn't support serialization natively
  • 2. Silverlight objects in binary form must be in a separate runtime. (double the fun)
  • 3. Each class in a Silverlight project must be echoed as a class on the server


Here is one way to resolve these problems and add a service layer to your .asp/mvc application.
I used these tools to complete the task: Subsonic for code gen, DimeBrain (huh?) Silverlight Serialization which is based on CSLA Light classes, Peter Bromberg's SharpLib for Silverlight

Here's what happens: The silverlight control has a member which is one of the classes marked for serialization that will have it's properties bound to controls for user manipulation. When the user pushes Save- this object is Serialized to Xml (DimeBrain), compressed (Peter Bromberg), base64'd (.NET), and UrlEncoded (.NET).
The resulting 'dried" data is then transmitted to the server in a form.POST request. In an MVC app, the url that is targeted looks like so: http://server/admin/data/classname


Again, using MVC, On the server within the targeted controller (admin), there is a method (data) which calls a function the purpose of which is to reverse the process used in Silverlight. UrlDecode, un-base64, uncompress, and deserialize the Request Stream to an object.


The xml representation that is received contains the name of the class which was serialized. These server side classes are generated code, (SubSonic!, using custom templates ) and have been added to the Server application's Business Logic layer. The end result is that there is a class on the server with the same class structure as the Silverlight object. And both of these data holders are created using Code Gen.

When this object has been "re-hydrated" so to speak, it's passed off to the correct data Repository for parsing into a server-side object (Entity Framework,maybe?) and placed into storage.
Once the wiring is in place, implementing additional control communications is a 45 minute job. Can that be any simpler?

Tags:

How To

Comments are closed

 

RSS Feed FriendFeed