views:

322

answers:

2

I'm developing a .NET application that will have both a WinForms and a Silverlight client. Although the majority of code will be in the server, I'll need to have quite a bit of logic in the clients as well, and I would like to keep the client library code the same.

From what I could figure out so far, I need to have two different project types, a class library and a Silverlight class library, and link the files from one project to the other. This seems kind of lame, but it works for simple code.

My problem, though, is that the code generated by the SVCUtil.exe to access WCF services is different from the code generated by the slsvcutil.exe, and the silverlight code is actually incompatible with the .NET one: I get a bunch of problems with the System.ServiceModel.Channel classes when I try to import the class into .NET.

Has anybody done anything similar to this before? What am I doing wrong?

+2  A: 

Unfortunately, as of Silverlight 3 and .NET 3.5sp1, there is no binary compatibility. You must share files, and maintain two separate libraries.

Silverlight 4 and .NET 4, however, will provide some level of binary compatibility. Depending on which assemblies you use in your client side, you may be able to use the same component in both Silverlight and Windows Forms.

Reed Copsey
Even without binary compatibility, though, isn't the idea that the silverlight libraries are a subset of .NET? In that case, wouldn't my silverlight code also compile under .NET 3.5?
Eduardo Scoz
It's not a strict subset, so no. :-( I normally use partial classes and preprocessor directives to work around that though.
Alun Harford
Thanks Alun, exactly what I was looking for.
Eduardo Scoz
A: 

Don't try and share a single proxy client amongst disparate clients - generate a proxy per client.

You can reuse the data classes between the projects using the add as link method you described. If a new version of the classes is created in the proxy, then you can just edit the generated proxy code files and delete out the class definitions. When you compile this up each client (Windows app and silverlight) will have its own version of the compiled class library, but it is all coming from the same source code.

kime waza