Friday, May 6, 2011

WCF / Silverlight : Reuse types in referenced assemblies

In my previous post I showed the smooth as silk streamlined process of reusing business logic contained in Domain Model objects over WCF in .NET 4. (linked here)

The process is silverlight is just as smooth. All you need is a silverlight library that contains the same files as in the DataModels as a linked file.

This is because you can obviously not add a .NET 4 library as a reference to a silverlight project as shown:
So create a new silverlight class library project:

In the class library project add your domain model classes as linked files :
And next add a reference to the silverlight class library in your Silverlight Application.
Now when you add a service reference and click on advanced options you should see the class library you added mentioned as shown:
If you do not see the silverlight class library you just created mentioned. You need to build your project first. 
That is all. If you did it right you will now see a DataSources folder under your Silverlight application properties as shown:

You can see that the right domain class is returned by the silverlight proxy generated by visual studio now (and I do get an exception as dictated by the business logic as I showed in part one)