WCF: Interfaces as DataContract (using Entity Framework as implementation of these Interfaces) RRS feed

  • Question

  • Can we expose an interface as DataContract of WCF service or Poco class is the only way, when data access project will be hosted on separate tier using EntityFramework behind the scene?

    Friday, May 4, 2012 12:06 PM

All replies

  • You will need to expose a concrete type over the interface. Keep in mind the WSDL has to be able to fully describe all of the data, and the client (assuming .Net) has to be able to construct one of the objects.

    The normal practice is to create a DTO class that does nothing but transfer data over the wire. In your service, populate the DTO with data from your EF POCO. On the client side, take that DTO and copy the data over to whatever your client actually needs.

    Check out My Blog. Now updated to actually work!

    • Proposed as answer by Fichtenelch Tuesday, May 8, 2012 7:57 AM
    Friday, May 4, 2012 7:29 PM
  • Hi,

    Tim is right, a DataContract has to be a concrete class. Interfaces are used for the ServiceContract.

    If you want to get to your EF Data over an WCF Service why don't you look at the "WCF Data Services"? These distribute your Entity Model over an WCF Service.


    Tuesday, May 8, 2012 8:00 AM
  • @Fichtenelch You Couldn't be more Right
    But in  "WCF Data Services" You Cannot Pass a non primitive types like a list of Objects
    or any complex Object
    You got stuck with only primitive types

    Monday, May 21, 2012 10:10 AM
  •  We Can pass , "list of Objects" If these objects are exposed as DataContract.

    Friday, October 12, 2012 1:02 PM