Shared Data Object Between WCF and Silverlight

I have a custom data object (data object) that opens through the WCF web service. The WCF service lives in a web application. Then I have a Silverlight application with a service reference for this WCF service. When I add a link to the service, a proxy is created and includes a version of the user data object.

How should I structure my code so that the data object is declared in one place and distributed among the project containing the WCF service and any Silverlight applications that reference it? I want to exclude the version of the data object generated by the proxy.

+4
source share
3 answers

There is a good example of how to do this here, Pete Brown . Using this approach, you can use the same classes for both the Silverlight client and the WCF service without using the generated objects.

+6
source

Declare the data entities in the WCF service or project that the service referee, and then from the Silverlight project add the entities as links and make sure that the "Reuse in reference assemblies" check box is selected from the "Service Link Settings" dialog box.

You can put types in the direction of Silverlight or WCF.

I tried doing it this way and found that instead of using DTOs and matching them with entities in Silverlight, they would be much cleaner and more convenient to work with, although I wrote a bunch of mapping code to get DTOs in entities and vice versa.

+1
source

I don’t quite understand why anyone wants to do this. You should understand that the type that you find in the proxy is a projection of the type that you have on the service server site. It is defined in * .g.cs files and is generated by a new one if you update the service link. In my opinion, this is the best way to declare it in one place and design it. You need it in two places, and it is defined separately.

Maybe I'm wrong.....

0
source

All Articles