locked
Data Layer with WCF in .NET 3.5 RRS feed

  • Question

  • What is the best practice of implementing a data layer in WCF? Is it necessary to build another data library for data access or it can put together? Any technical or security concern?  TIA.
    Wednesday, October 14, 2009 6:32 PM

Answers

  • You can use this blue print from Microsoft on MSDN- http://msdn.microsoft.com/en-us/library/cc304695.aspx

    You can improvise on top of this based on your particular requirements.


    Also check using Web Service Software Factory. Personally it hels in initial stages of the project to set the basic solution structute and gives shape to the project.
    http://www.codeplex.com/servicefactory

    http://servicefactory.codeplex.com/Project/Download/FileDownload.aspx?DownloadId=5530


    Thanks,
    -Phani
    • Marked as answer by Bin-ze Zhao Monday, October 19, 2009 10:49 AM
    Thursday, October 15, 2009 6:57 AM
  • I would use the concept of Layering and Separation of Concerns.  I've developed an application that uses WCF for the Service Layer, as well as separate Domain and Data Access Layers using Domain Driven Design, the Repository and Unit Of Work patterns, along with NHibernate to interface with various types of databases (SQL Server, Oracle, MySQL, etc.).  I have a set of Service methods, implemented for use with WCF, that call various "service" methods in the Domain Layer for basic CRUD operations.  These Domain Layer methods then access the data through a Repository and Unit Of Work, which then interfaces with NHibernate, or an in-memory Repository that I've created for TDD purposes,  to do the actual database operations.  

    This type of architecture is considered a best-practice.  It may seem like alot of work, which it is, but you will end up with a much more flexible and extensible architecture for your application.

    Thanks,
    Ron Kanagy

     


    • Marked as answer by Bin-ze Zhao Monday, October 19, 2009 10:49 AM
    Wednesday, October 14, 2009 7:43 PM

All replies

  • I would use the concept of Layering and Separation of Concerns.  I've developed an application that uses WCF for the Service Layer, as well as separate Domain and Data Access Layers using Domain Driven Design, the Repository and Unit Of Work patterns, along with NHibernate to interface with various types of databases (SQL Server, Oracle, MySQL, etc.).  I have a set of Service methods, implemented for use with WCF, that call various "service" methods in the Domain Layer for basic CRUD operations.  These Domain Layer methods then access the data through a Repository and Unit Of Work, which then interfaces with NHibernate, or an in-memory Repository that I've created for TDD purposes,  to do the actual database operations.  

    This type of architecture is considered a best-practice.  It may seem like alot of work, which it is, but you will end up with a much more flexible and extensible architecture for your application.

    Thanks,
    Ron Kanagy

     


    • Marked as answer by Bin-ze Zhao Monday, October 19, 2009 10:49 AM
    Wednesday, October 14, 2009 7:43 PM
  • Hi,

    The architecture which we use is more or less similar to the one mentioned by Ron with the emphasis on separation of concerns and loose coupling. It would be better have your data layer in a separate assembly. Have your service layer call the data layer through your business layer. Service layer must access the data layer directly.
    Thursday, October 15, 2009 12:37 AM
  • You can use this blue print from Microsoft on MSDN- http://msdn.microsoft.com/en-us/library/cc304695.aspx

    You can improvise on top of this based on your particular requirements.


    Also check using Web Service Software Factory. Personally it hels in initial stages of the project to set the basic solution structute and gives shape to the project.
    http://www.codeplex.com/servicefactory

    http://servicefactory.codeplex.com/Project/Download/FileDownload.aspx?DownloadId=5530


    Thanks,
    -Phani
    • Marked as answer by Bin-ze Zhao Monday, October 19, 2009 10:49 AM
    Thursday, October 15, 2009 6:57 AM