.Net n-Tier Data Access Layer

Posted on 2012-09-11
Last Modified: 2012-09-12
Hello all

I manage a system which has several different winform front ends used at multiple locations.

Admittedly when I first created the system I didn't understand much about OOP or n-tier design so it's all a bit of a mess.

I did plan on creating a web service which would act as the DAL/BL but upon further reading I hear this isn't the best idea, performance being an issue for one thing.

So what's the best way of going about this? I don't want to move to a web based version of the front ends as it doesn't give me the flexibility that I require as I often need to access different types of hardware directly. But I'm uncomfortable having all of the data access code in the program and for it to be accessing the database directly. It also creates more work having to update all of the programs individually.

Should I just take the limitations of and performance issue of using a web service to do this as unavoidable?

Many thanks
Question by:badpilot
    LVL 18

    Accepted Solution


    Firstly you can create WinForms apps using web services with absolutely no issues. I actually prefer WinForms apps over WebApps but thats just a personal preference.

    I did plan on creating a web service which would act as the DAL/BL but upon further reading I hear this isn't the best idea, performance being an issue for one thing.

    One of the reasons that you would use a distributed architecture is that it allows scalability. This means that you can add more servers into the mix if you found that you needed better performance. All of the hard work is done on there server which means that your PC's do not have to do the donkey work. This is handled on the server where you've probably spent alot of cash on with multiple processors etc...

    I would also suggest that the performance hit with todays PC/Server speeds is a non issue unless you are doing something very computationally intensive, which, again should be done on there server.

    Using WCF you can connect to your service using HTTP or TCP depending on what you want to do. You can also connect using various other protocols so it doesn't havce to use a web server (although you would have to create your own server for other protocols)

    Another reason is maintenance which you pointed out. You currently have to update the code base across multiple exe's. Keeping all business logic in one place is a good idea.

    Accessing hardware connected to a PC is different and would probably require some of the code base to stay within the exe.

    There are many more reasons for using a distributed architecture The simple fact remains if you need a distributed architecture then create one otherwise don't. This is one of those
    It Depends

    Let me know if you require more info.

    Hope this helps,

    LVL 83

    Expert Comment

    WCF is would be better option than web services. You can also just separate the DAL/BL into separate DLL(s) and it will save you from having to make changes to all programs for changes in DAL/BL.

    Author Comment

    Thanks, I think I was just looking for re-assurance that this was the correct path to take. The system (as is usually the case in these situations) has grown organically which is why I've gotten to this point.

    One more question if you will - I understand that performance wise, error checking/validation should be placed in the UI layer as to reduce the number of calls to the service - this seems counter-intuitive though as it would require an understanding of how the service operates.

    Should I just get this idea of performance out of my head and place all of this on the server? Computing power isn't an issue but the connections used for these applications in some of the remote locations are ropey at best. I suppose I'm concerned about time outs/duplication of data/support calls.

    Thanks again.
    LVL 18

    Expert Comment

    Hi badpilot,

    I normally perform all of the validation on the server.

    I have a single method that checks all of the data sent up the wire and validats it. If there are errors then the error fields are sent back in a message. So if there were two incorrect pieces of data set back one error message with both of the validation messages in it.

    You can check some of the data on the client if you want like numeric only fields to stop incorrect input but that's about all I do.

    If some of the connections are ropey then you may have to look at other options... I've used WCF where our offices have simple broadband connections and it all seems ok, however, if you are talking dialup or something like that then maybe you will have to keep a local copy of the database and sync this up when the connection is idle e.g. at night....

    Again, these are the "it depends" questions as we only have so much of your knowledge to go on...



    Author Closing Comment

    Thanks very much for your help, greatly appreciated.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Highfive Gives IT Their Time Back

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    This document covers how to connect to SQL Server and browse its contents.  It is meant for those new to Visual Studio and/or working with Microsoft SQL Server.  It is not a guide to building SQL Server database connections in your code.  This is mo…
    Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
    It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
    Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

    779 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    12 Experts available now in Live!

    Get 1:1 Help Now