The choice between creating a web or desktop application is one of the first design decisions made for any project. Previous development technologies had a fairly clear demarcation between the two categories. Web applications run on a web server and receive requests from, and serve web pages to, users running a browser on their local machine. Windows applications, on the other hand, are generally executed independently on the local machine, although there might be network resources brought to bear, such as remote databases.
This book focuses on Windows applications and rich-client web applications. For a complete discussion of ASP.NET web applications, please see Programming ASP.NET, Second Edition (O'Reilly).
With the .NET Framework, this distinction between the two categories is considerably blurred. Rich-client Windows applications may interact with servers using web technology. Web applications may use controls that run on the user's machine. The distinctions between desktop and network and network and Internet, are less crisp than they were a few years ago.
While web applications still run on a web server and Window applications still run on the local machine, many strengths formerly of one modality or the other now apply to both. The "right" decision is not always so clear cut.
You need to consider many issues when deciding whether to build a Windows or a Web application:
Web applications are, admittedly, easier to deploy than Windows applications. Update your server, and you're done. On the other hand, .NET desktop applications are far easier to install than previous Windows applications.
There is no need to register applications or DLLs with the local Registry, and all configuration is self-contained within the program's directory. This leads to XCopy deployment. To install an application, you only need to copy the directory structure containing the application to the target machine.
Deployment of Windows applications will be covered in detail in Chapter 22.
It is now possible to have multiple versions of the same DLL on a single machine, with each application using its own version. The same application can even access different versions of the same DLL in the same directory (although we definitely do not encourage this practice).
This means the end of DLL Hell, in which you install a program with a new DLL and an unrelated program breaks. With .NET, DLL Hell should be a thing of the past.
It is even possible to pull the installation of a Windows application across the Internet. Every time your application runs, it will check a web site for updated components, and if any are found, automatically download and install them.
Windows applications are usually, although not always, faster than web applications. Every request from a browser requires a trip to the server and back. Often this roundtrip occurs over a relatively slow connection. Even DSL (1 MB per second or more) or a T1 (1.544 Mbps) is slow compared to a local network connection (typically 100 Mbps), which itself is slow compared to a local hard drive (up to 100 MB per second, equivalent to 800 Mbps)
ASP.NET improves performance significantly over previous web technologies. It does this by using compiled, rather than interpreted, code modules, and by minimizing the number of roundtrips required. Still, the performance yielded by a web application depends on the speed and condition of the Internet (or intranet) connection and the current load on the server. Even the fastest servers or web farms will bog down if overwhelmed with requests.
In some types of applications, a web application might have a speed advantage over a local application—one with a fast connection, a very fast server, and processing time that is more significant than the access time. For example, suppose you are developing a research application in which a user can make ad hoc queries against a large database. The application could be run either directly from a CD, installed to and run from the local hard drive, or as a web application via a browser. In this situation, it is very possible that a web application, running over a T1, DSL, or cable modem, would be faster than a Windows application running against a database residing on a CD. A web application hitting a very powerful, optimized database server might also be faster than a Windows application installed on the local hard drive if the queries were very complex and time consuming to process.
User interface is one advantage of using Windows applications over web applications. Let's face it, a browser UI is usually pretty clunky compared to a Windows UI. ASP.NET goes a long way toward improving this situation, and the use of client-side scripting for the browser closes the gap even further. Still, it is much easier to develop a rich, smooth, and satisfying (sounds like a coffee commercial) user experience in a Windows application than in a web application.
This is because web controls are limited to fewer than a dozen events, while Windows Forms controls have access to many times that. Every time an event is raised in a web application, a roundtrip to the server ensues (unless client-side scripting is used). Raising and responding to ubiquitous Windows events such as MouseEnter or TextChanged is too time consuming.
The end result is that Windows applications give the developer the ability to respond more finely to user actions.
Well-designed web applications are very secure, a fact upon which much of the modern economy depends. ASP.NET further improves web security. Still, anytime you send information over the wire, it is at greater risk than data that remains on your computer's internal data bus.
Widespread adoption by users remains one area in which web applications have a clear advantage over Windows applications. Thanks to the ubiquitous web browser, web applications are easily available to anyone with access to an internet connection. Users don't have to decide to install an application, they just use it. With Internet deployment of .Net Windows applications, this gap is narrowed somewhat, but it is still easier to penetrate a mass user base with a web application than with a Windows application.
In addition, even if the .NET Framework were installed on 100 percent of the machines in the world running a Microsoft OS, there would still be many users outside the fold (such as users of Mac, Linux, Sun OS, and countless other platforms, who can access a browser application but not a Windows Forms application). Although it is the stated goal of .NET to be ported to other platforms (rumors of an imminent Linux port abound), this obstacle will always limit the maximum size of the potential user base.
Web services is a technology that blurs the distinction between web and Windows applications. A web service allows either a web or Windows application to programmatically access a web server, without requiring direct user interaction. This opens up Internet-enabled, wide area access to data and programmatic functionality for Windows applications.
Creating a Windows application that interacts with web services provides worldwide access to data and services coupled with a rich user interface.
For a complete discussion of web services, see Programming ASP.NET, Second Edition (O'Reilly).