Visual C#. NET 2003 Unleashed
|
With the gaining popularity of the Web, it is becoming increasing important, if not expected, to be able to download and run applications by simply going to a website. .NET provides several mechanisms for you to make this task easier. You can choose to deploy an application from a URL or your can create a smart client application that is capable of downloading itself. Deploying from a URL
One of the coolest things with .NET is the attempts that the Framework makes to resolve the locations of an assembly it wants to bind. Because the Framework looks in so many locations, and one of them is the application base, you can simply set up an application for deployment from a URL by dropping all the required assemblies in a folder on the web server. To illustrate this point, take SimpleApplication.exe and the assembly that it references, SimpleApplicationLibrary.dll, and place them in a folder called SimpleExample off of the root of your web server. TIP Because the web server that you use to deploy your application simply serves as a distribution mechanism, you do not need to have the .NET Framework installed on that web server. In fact, the web server does not even have to be a Windows machine.
When the files are in this folder, you can open the Internet Explorer and, as shown in Figure 20.1, type the following URL: http://localhost/SimpleExample/SimpleApplication.exe
Figure 20.1. Requesting the SimpleApplication example from a URL.
When the application appears, click the button and a message should appear, as shown in Figure 20.2. The text for this message is not contained within the SimpleApplication.exe application, but is stored in the SimpleApplicationLibrary.dll assembly. This shows that the .NET Framework not only downloaded the requested file, but when needed, also downloaded the required assembly. Figure 20.2. Requesting the SimpleApplication example from a URL.
Deploying Smart Client Applications
A smart client is an application that captures the best features of rich client and web client applications and adds to them. One of the features of a smart client is that it is centrally deployable and self-updating. That means when a smart client is deployed, the assemblies and required files should be deployed in one location and the client application should be capable of retrieving all the necessary files from that location. It also means that if any of the assemblies are updated, the smart client should be capable of detecting that a newer version is available and retrieve that version of the assembly. Unlike the example in the previous section, when the application was started from a URL and it automatically loaded the referenced assembly from that location, a smart client application is generally stored on the user's machine. When the smart client application starts, it checks a predefined location for the required assemblies and if a newer version is available, it downloads this version to the client machine. In .NET, this is possible by using the Assembly.LoadFrom Listing 20.5. Psuedo Smart Client Application
using System; using System.Drawing; using System.Collections; using System.ComponentModel; using System.Windows.Forms; using System.Data; using System.Reflection; namespace PsuedoSmartClientExample { /// <summary> /// Summary description for Form1. /// </summary> public class Form1 : System.Windows.Forms.Form { private System.Windows.Forms.Button button1; /// <summary> /// Required designer variable. /// </summary> private System.ComponentModel.Container components = null; public Form1() { // // Required for Windows Form Designer support // InitializeComponent(); // // TODO: Add any constructor code after InitializeComponent call // } /// <summary> /// Clean up any resources being used. /// </summary> protected override void Dispose( bool disposing ) { if( disposing ) { if (components != null) { components.Dispose(); } } base.Dispose( disposing ); } #region Windows Form Designer generated code /// <summary> /// Required method for Designer support - do not modify /// the contents of this method with the code editor. /// </summary> private void InitializeComponent() { this.button1 = new System.Windows.Forms.Button(); this.SuspendLayout(); // // button1 // this.button1.Location = new System.Drawing.Point(104, 96); this.button1.Name = "button1"; this.button1.TabIndex = 0; this.button1.Text = "button1"; this.button1.Click += new System.EventHandler(this.button1_Click); // // Form1 // this.AutoScaleBaseSize = new System.Drawing.Size(5, 13); this.ClientSize = new System.Drawing.Size(292, 266); this.Controls.Add(this.button1); this.Name = "Form1"; this.Text = "Form1"; this.ResumeLayout(false); } #endregion /// <summary> /// The main entry point for the application. /// </summary> [STAThread] static void Main() {
|
|