Easy way to expose Northwind Database with WCF? RRS feed

  • Question

  • I see that Entity Framework (database first) and LINQ to SQL create a lot of classes for you (when using the Visual Studio code generation).

    How can I create a WCF Service with methods that return arrays of orders or customers or regions etc... (there are quite a few classes in the Norhtwind database)...

    Is it necessary to type in each class over again with the [DataContract] attribute making a additional set of classes that are almost redundant with all the classes that Linq to SQL or Entity Framework has already created?

    Yikes! If this is true, I must say there is some merit to the old asmx files with ADO.NET. You can just use ADO.NET to populate a dataset and return that.

    Now I know I could use the OData feature, but that is read only at this time. Furthermore, I might want to put some custom logic in each method.

    In summary: is there a way to create a WCF service where I don't have to type in all the classes using the [DataContract]?

    Maybe there are some tt files I could modify somewhere to put the DataContract in the files that Visual Studio generates?



    siegfried heintze

    Wednesday, June 18, 2014 1:19 AM


All replies

  • You are getting serialized XML data so you can always parse the XML in code rather than do the automatic parsing using DataContract.


    Wednesday, June 18, 2014 2:17 AM
  • Using the EF DataBase first approach, an EF Entity on the virtual model is an implicit datacontract with WCF. So you can send those entities through WCF client/service as is, and it would not be a problem.

    On the other hand, most don't send the EF entities through WCF. They send DTO(s) Data Transfer Objects.

    The beauty of EntityToDTO(s) is it creates DTO(s) that are datacontracts to WCF, which means to you is that you can create a classlib project call it Entities that will hold the DTO(s) and all projects can set reference to Entities and use the DTO(s).

    • Marked as answer by siegfried_ Wednesday, June 18, 2014 5:25 PM
    Wednesday, June 18, 2014 3:16 AM