Eduardo Scoz
Eduardo Scoz

Reputation: 24743

Shared WCF client code between .NET and Silverlight apps?

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?

Upvotes: 3

Views: 754

Answers (3)

Ahmed Ghoneim
Ahmed Ghoneim

Reputation: 7057

I know it's too late to provide a solution but it was my problem too and I found Portable Class Libraries. It's a perfect solution to your issue.

Upvotes: 2

kime waza
kime waza

Reputation: 511

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.

Upvotes: 0

Reed Copsey
Reed Copsey

Reputation: 564363

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.

Upvotes: 2

Related Questions