Huzefa Kagdi Huzefa Kagdi - 3 months ago 64
ASP.NET (C#) Question

Interaction between WCF, DAO and DTO layers in ASP.NET application

Can someone guide me in how the WCF, DAO and DTO layers communicate with each other? I would appreciate if someone can specify which layer comes first and then how it interacts with the next layer and so on.

Answer

Looks like you have no idea what do these terms mean. First of all non of them is a "layer".

  • WCF - Windows communication foundation - MS technology for building service oriented applications
  • DAO - Data access object - object exposing operations to interact with database (load object, save object, etc.) but internally hiding details about database.
  • DTO - Data transfer object - special type of object used to tranport data from one layer/tier to other layer/tier.

So example usage of these terms in real architecture can be:

Data Tier (Db server)

  • Running database

Business Tier (Application server)

  • Data access layer using DAO to access DB and to hide DB details from higher layer.
  • Business layer using data access layer to access and persist data. Running all domain logic, workflows, business rules, etc.
  • Service layer implemented in WCF exposing business operations from business layer. Service layer exposes web services which use DTO to transfer data. Domain / business objects are converted to and from DTOs.

Presentation Tier (Web server)

  • Presentation layer - ASP.NET application using service layer to communicate with business tier. Service layer and presentation layer exchange only DTOs.

This architecture is only for big projects. Usually you don't need to separate presentation and business tiers and so you don't need WCF service layer. In such case your presentation layer can access business layer directly without using DTO.

Edit:

Based on your comments I'm adding these informatios.

  • NHibernate's Session can be called DAO because it provides operations to interact with DB but it also hides DB's details.
  • When using NHibernate you have set of classes which can be persisted to DB based on defined mapping. NHibernate stores and loads these objects. You can add some logic (methods) to these classes and call them Domain/Business objects.
  • DTO is special type of object which doesn't have any logic. It is juse crate for data. It is usually designed to transfer only data the operation actually needs (for example you will not transfer whole customer objects if you only need names and emails). DTO should be also designed to transfer data from multiple business objects to reduce roundtrips between client and service.
Comments