views:

314

answers:

3

I've been designing quite a few Windows Forms applications lately (data-entry apps, office integration, etc), and although I've always designed with logical tiers in mind, the "middle tier" business logic layer has always been hosted on the desktop PC (i.e. physical client-server).

As I approach more complex applications, I find myself yearning for a physical middle tier instead, with the desktop client passing requests back to an application server to process business logic (which may change regularly) and interfaces. It feels like I'm missing out on factors such as scalability and maintainability that are more native to Web apps.

I'm curious to know how far other WinForms developers have taken their middle-tier separation:

  • How much processing (if any) do you perform on a middle-tier server?
  • What communication method are you using - WCF, remoting, web services, etc?
  • How much is performance a factor, and how often do you roundtrip to the server?

Is there are a benefit in moving business logic onto a separate tier, or is it more practical to host components locally on a PC (and just make sure you have a good deployment model to push out regular releases as business rules change)?

Alternatively, should I be guiding customers away from WinForms completely if these factors are involved? With alternatives such as Silverlight and even ASP.NET w/ AJAX, the reasons to choose a WinForms client seem to be shrinking.

A: 

Depending on your application, there are several performance issues to keep in mind.

If your work is very similar between various clients (shared data), then doing the processing on a middle tier is better because you can make use of caching to cut down on the overall processing.

If your is different between clients (private data), then you won't have much gain by doing the processing at a middle tier.

chills42
+1  A: 

This is one example of why I tend to always do work in a web environment. If the network is available to your client application for service calls, it's certainly available to send and retrieve data from a web server.

Certainly, client restrictions can alter your final path, but when given the chance to influence the direction, I steer towards web-based solutions. There are deployment technologies available that give you an easier upgrade path than a traditional desktop package, but there's no real substitute for updating a server-based application.

Chris Stewart
I certainly see the benefits of the web environment, but I guess I'm pondering whether its feasible to have 'best of both worlds' by wiring up a WinForms client to talk across services to some server-based logic. This is only for when you've got strong WinForms constraints like heavy office-integration obviously...
Soundwave
I can understand your point. It could certainly work where you have a collection of web services that sit on a server that do the real work, persist data, etc.Think of your WPF/WinForms as a thin client with web service connections. That way you'll keep the benefit of a rich UI. However, you're not truly gaining any of the maintenance benefits that you traditionally see in web applications. You can alter functionality and behavior at the web service level, but adding functionality would require a UI refresh. There are some newer deployment tools for client applications they may help.
Chris Stewart
+2  A: 

What is important to keep in mind is that there is a trade-off between the ease of development with a seperate middle tier vs all of the scalability benefits etc. What I mean by this is that you have to refresh interface mappings etc in your code, you have to deploy a middle tier somewhere for your testers to use, which needs to be refreshed etc. Furthermore, if you are lazy like me and pass your Entity Framework objects around directly, you cannot serialise them to a middle tier, so you then need to create DTO's for all of your operations etc.

Some of this overhead can be handled by a decent build system, but that also needs effort to set up and maintain.

My preferred tactic is to keep physical seperation in terms of assemblies (i.e. I have a seperate business logic / data access assembly) and to route all of the calls to the business layer through an interface layer, which is a bunch of Facade classes. So all of these assemblies reside within my windows app. I also create interfaces for all of these facades, and access them through a factory.

That way, should I ever need the separation of a middle tier, and the trade-off in terms of productivity is worth it, I can separate my business layer out, put it behind a WCF service (as that is my preferred service platform) and perform some refactorings in terms of what my facades hand out, and what they do with what they accept.

Joon