Section 3.9. Enable One-Click Deployment


3.9. Enable One-Click Deployment

Many would argue that web applications have a huge advantage over Windows applications in that they can be distributed so easily (at so little cost). Some developers and clients have been frustrated, however, that the browser limits their control over the user interface, and thus the idea of a smart client (sometimes called a rich client, but not to be confused with the thick clients of the client-server era) was born.

A smart client is a Windows-based application that you can deploy by asking your users to click a link presented in their browser. A smart client uses the power of Windows on a desktop Windows machine to provide a richer user experience than is possible with a web browser, and in this regard it resembles a traditional Windows application. But unlike a Windows app, a smart client is distributed to users via the Web (holding down distribution costs) and uses centralized data (and possibly some processing) via one or more web services. A smart client application is essentially a web application that is viewed through a rich client-side application and is distributed and updated using web protocols.

3.9.1. How do I do that?

The key to creating a smart client is a new technology called click-once deployment, dubbed ClickOnce by Microsoft. ClickOnce allows your customer to download your application to a local machine. When you update your application on your server, the client is notified and is offered an opportunity to update.

To see this cool new feature at work, create a new Windows application project and call it ClickOnce. Drag a label and a button control onto the application form. Double-click the button and add this line of code:

label1.Text = "Hi.";

Run your application to make sure it works. This simplistic application will stand in for the rich client you would normally create.

Your next step is to build the application for ClickOnce distribution by choosing Build Publish ClickOnce, as shown in Figure 3-28.

Figure 3-28. Publishing your ClickOnce application


This menu choice brings up the Publish Wizard, where you can indicate the virtual path from which your application will be distributed, as shown in Figure 3-29.

Figure 3-29. Specifying the ClickOnce location


Once you set the virtual path, the second step of the wizard asks if you want to make the application available online or offline, or only for use online. Typically users choose to make the application available online or offline (see Figure 3-30).

Figure 3-30. Choosing availability


The third and final step is to create a strong name for your application. You have a choice at this point to either have the wizard generate a strong name for you or use a key provider that you have already established.

When you click Next, the wizard reviews your choices and informs you that when the application is installed on the client machine, a shortcut will be added to the Start menu, and that your application can be uninstalled from the client machine using the Add/Remove programs.

Then the wizard opens a browser and navigates to the default download page for your application, as shown in Figure 3-31.

Figure 3-31. The Publish page for the ClickOnce application


If you click Install ClickOnce and install the application, you'll find that it is now listed in your start menu, as shown in Figure 3-32.

Figure 3-32. The application installed on the Start menu


3.9.2. What about...

...when you update a ClickOnce application on your server?

ClickOnce makes the update available the next time the user tries to use the application if the user is connected to the server (via the Internet or a local area network).

To see this at work, return to the application and change the Click handler:

label1.Text = "Updated.";

Repeat the previous steps using the Publish Wizard.


Tip: When you get to the set for the key, use the key already assigned to the application (this will be the default). This indicates that the newly built application is a replacement, not a new program.

The next time the user runs your application, the Update Available dialog will be presented, as shown in Figure 3-33.

Figure 3-33. The Update Available dialog


Click OK. Your program is updated and when you run it you will see the new behavior.

3.9.3. Where can I learn more?

O'Reilly's ONDotnet.com site has a good article on ClickOnce at http://www.ondotnet.com/pub/a/dotnet/2004/10/11/clickonce.html. Also check out "Deploy and Update Your Smart Client Projects Using a Central Server," by Brian Noyes, in MSDN Magazine (http://msdn.microsoft.com/msdnmag/issues/04/05/ClickOnce/).



Visual C# 2005(c) A Developer's Notebook
Visual C# 2005: A Developers Notebook
ISBN: 059600799X
EAN: 2147483647
Year: 2006
Pages: 95
Authors: Jesse Liberty

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net