On 7/9/2012 1:29 AM, Philip Wright wrote:
> I have a WPF client application that connects to IIS that hosts WCF Data
> Services and WCF Services.
>
> Ideally I would like to define a single class that represents a User and
> then be able to reuse that same class implementation in both the WPF
> client and web server projects. Therefore my validation code and helper
> methods are implementation and unit tested just the once in one place.
> For example...
>
> 1, WPF client calls a WCF Services operation and gets back a User entity.
> 2, WPF client calls WCF Data Services and gets back a User entity.
>
> Is is possible to get WCF Data Services using the same User class as the
> WCF Service and Entity Framework.
>
> If so is it via self tracking entities, POCO classes or some other option?
>
I don't think you are going to get this to work for the following reasons:
1) The entities are in two different namespaces.
2) Data Services are locked on what it needs as an entity.
The best you could do is use a DTO (Data Transfer Object) like
DTOUser.cs in a classlib project that both services reference the
project, see the DTO(s), and map data to from the DTO(s) and send them
between two service types with Service Layers (Service Layer classlib
projects) for both services to pass the DTO(s).
Using the same EF objects between two WCF services may not be workable.
I also consider a POCO a glorified DTO.