.Net n-Tier Data Access Layer

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
Who is Participating?
DarrenSenior Software EngineerCommented:

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,

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.
badpilotAuthor Commented:
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.
DarrenSenior Software EngineerCommented:
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...


badpilotAuthor Commented:
Thanks very much for your help, greatly appreciated.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.