Using Web Services in a 3-tier architecture

During the age of the Windows DNA, most of us developers used COM/COM+ and a 3-tier architecture. Where we separate concerns by placing the views to present data into a layer called PL (Presentation Layer), we add all business logic into one single layer called BLL (Business Logic Layer), all code that handle data access was also placed into its own layer called DAL (Data Access Layer). During this time when Windows DNA was a hot topic, most application used this architecture.


3tier


By using DCOM it was easy to distribute the different components in the layers into distinct tiers. DCOM had its advantage and also disadvantage (DCOM hides the "distribution" and distribution could be done after application was written without the developers awareness, most applications wasn't designed for distribution purpose.). There was few application I was involved with that used DCOM, and I will in this article focus on the application that didn't use DCOM. The 3-tier architecture was well defined and common used. Several applications today used this architecture. When .Net arrived several developers was scratching their heads, it was a whole new platform for most of them and a difficult and confused time began, "how should this 3-tier architecture be applied on the .Net platform?". Web Services was introduced somewhere around this time and that was a bright light for some solution architects and developers, now they understand how to apply the 3-tier architecture on the .Net platform, the answer was to replace COM/COM+ components with Web Services. So instead of using a binary standard for the communication, XML and HTTP was used.

3tier_WebService


Even today several applications uses the 3-tier architecture with Web Services as a replacements for COM/COM+ and even a replacements for DCOM and that is understandable. But replacing COM/COM+ with Web Services for applications on a single machine, with no reuse or integrations with other applications in mind, is something that make me sad. Now when we have WCF (Windows Communication Foundation), developers start to replace Web Services with WCF. There are several applications running on a single machine with no attention of integration with other systems that uses different WCF Services for the Business Logic and the Data Access. I will not say that this is totally wrong decision made by architects, but it will affect performance and scalability, and can affect it badly. There is absolutely no reason to use WCF Services if the application is running locally or on a single machine where no integration with other systems are of interest. Even if there are integration in mind, there is no reason to have the Data Access Layer as a WCF Service, because most applications will reuse the business logic, so the layer top of the Business layer should be a WCF Service not the underlying layers. There are some exceptions, if we have moved the Data Access Layer into a distinct tier, and several applications should reuse or have access to the same data source; but can't or aren't allowed for a direct connection to the data source, the Data Access could be implemented as a WCF service. In that case all communication will go via the WCF Service.

If there is no reason of using Web Services or WCF Services as a replacement for COM/COM+ in applications with not interest in integration, what is the solution? A simple Class Library! Best performance, easy to add, easy to implement. Since .Net arrived I toke the advantage of the platform and use Object Oriented Programming. Now during the past few years I have adopt Domain Driven Design. How about you, do you still use the 3-tier architecture and using Web Services of WCF, or something else?

5 Comments

  • The cost of this architecture is not only performance, but in the amount of unnecessary code and complexity that comes with a distributed solution (DTO objects, duplicated domain objects, transaction and error handling, etc).

    If there is no need to distribute then taking this cost is an extreme YAGNI design point :)

  • Don't agree fully, maybe the scenario wasn't the same when we started using WCF services in my previous job but let me try to explain. We had to control PLC machines in sawmills from a windows forms application. The thing with the PLC control libraries is that it is extremely deeply integrated with the core of the cpu. This caused alot of problems with our windows 32 forms application. The .NET wrapper we used for communicating with the PLC was not very reliable in some scenarios.

    I am not saying it was a painless effort moving to wcf services but it was really worth it. Speed increased alot and it is not nearly as painfull as com+ programming. It just made sense somehow :)


  • @Torkel:
    Absolutely, even if WCF doesn’t hide the distribution, people will still use it as it was a ”local” API, but the one part I like with WCF is the default limit of how much data you can pass, so as a developer you need to increase this number if you returns a list of data. In this case they may do some extra thinking (hmm, am I doing this in a correct way?).

  • so the final point is if i design a web application for a company or a retail store should i design the 3 tier architecture with only class library or should i use web services for BLL

  • Great, exactly the post I was looking for.

    If I understand you correctly, "don't distribute your objects if you don't need".

    But I have a question : "Does the interoperability the only cause to create web services?"
    for example, won't you take care of deployement:
    • don't want to install driver of database on all client machines
    • don't want to give access to the database server to all client machines

    Additional question:
    How would you decide to use standalone or silverlight application? Indeed Silverlight application involves web services.

    Thanks in advance for your answer.


Comments have been disabled for this content.