WCF and the creation of ViewModel

Topics: Prism v2 - Silverlight 2, Prism v2 - Silverlight 3
Dec 23, 2009 at 7:15 PM


I've started the multi-target process of adding a Silverlight client to my previous WPF only app.  Part of that process was getting my data to the Silvelight client via WCF.  I only need to share/expose a couple of ObservationCollections that the ViewModel owns/maintains.  I started of by creating a interface/ServiceContract with one method called  GetFilteredFoo() that returns the ObservationCollection<Foo>.  I then slapped the IViewModel interface on the implementation of my ViewModel which already provided the functionality.  I then wondered how do I host my ViewModel as this service that exposes my one observation collection.  To "start" a service you typically would use ServiceHost, supply the Type and Interface, and then call open.  Voila, WCF instantiates the object.  How do I get access to it to bind it back to my view and or datamodel.  In my WPF only app, the Foo Module created the ViewModel and bind it with the View and Datamodel.  Of course I hadn't considered all of the WCF PerCall, PerSesssion, Singleton issues that effect how the service object is created.

I started looking into Unity and then realized perhaps I'm trying to jam to much responsibility onto the ViewModel. 

BTW the WPF app is full featured.  The silverlight page is going to be a read-only view of a subset of info that is being shown in the WPF views. 

My gut is telling me this is getting too complicated and I must be architecting/designing this incorrectly.