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?

Published Wednesday, November 05, 2008 9:57 PM by Fredrik N
Filed under: ,

Comments

# re: Using Web Services in a 3-tier architecture

Wednesday, November 05, 2008 4:27 PM by Steve

Good point!

I have loved this architecture here, I'm using asp.net mvc:

Web

Controller (separate assembly)

Services (not web service or wcf - but could be if it moves)

Domain (I have this shared across the layers)

Data (my Dao objects - I use NHibernate)

Basically this:

biese.files.wordpress.com/.../spring2-01.JPG

# re: Using Web Services in a 3-tier architecture

Thursday, November 06, 2008 1:35 AM by dkl

You're right. Distribution boundary must be explicit in code, as it is serious performance and stability threat. I prefer messaging-based solutions for distribution, like http://www.nservicebus.com/

# re: Using Web Services in a 3-tier architecture

Thursday, November 06, 2008 2:40 AM by Torkel

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 :)

# re: Using Web Services in a 3-tier architecture

Thursday, November 06, 2008 2:40 AM by Mikael Henriksson

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 :)

# re: Using Web Services in a 3-tier architecture

Thursday, November 06, 2008 5:10 AM by Fredrik N

@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?).

# re: Using Web Services in a 3-tier architecture

Thursday, November 06, 2008 12:00 PM by Andreas Öhlund

I'm doing alot of DDD and the onion architecture works well for me:

jeffreypalermo.com/.../the-onion-architecture-part-2

# re: Using Web Services in a 3-tier architecture

Tuesday, November 11, 2008 5:16 AM by Jen

Helpfull blog...

# re: Using Web Services in a 3-tier architecture

Wednesday, November 12, 2008 7:16 AM by Simon Ince

Interesting post - I commented about this kind of thing in a slightly wider context of "build only what you need", but used the habit of adding needless service layers to architectures as an example, so I whole-heartedly agree with you. Check out my comments here;

blogs.msdn.com/.../sufficient-architecture.aspx

Simon

Leave a Comment

(required) 
(required) 
(optional)
(required)