|
|
YOUR FEEDBACK
|
TOP MICROSOFT .NET LINKS Windows Forms Controls
Making Windows Forms Work with Legacy Web Applications
A pattern that uses .NET 2.0 and ClickOnce
By: Guy Starbuck
Nov. 18, 2005 11:00 AM
Digg This!
Page 1 of 2
next page »
This article describes a pattern that allows any Web site or Web application to launch and interact with .NET 2.0 Windows Forms applications that are deployed using Microsoft's new "ClickOnce" technology. This is done by taking advantage of a feature that allows Windows Forms applications that are deployed using ClickOnce to receive querystring parameters.
Over time, Web UI and functionality has improved. However, there is one place where Windows Forms applications are vastly superior. The user interface can be tuned, customized, and made extremely efficient. A Web application is always going to require more mouse clicks and key presses for a business user to perform their job than a custom Windows Forms application with its infinitely customizable hotkeys and UI layouts. The release of Visual Studio 2005 and .NET 2.0 is a major shift back to Windows Forms. Microsoft's new Windows Forms deployment technology, ClickOnce, is targeted expressly at eliminating the drawbacks of Windows application deployment. This technology automates the deployment process and ensures that all users are running the same version of the application. IT departments can deploy software and patches to one central server just as they have done with Web applications in the past.
ClickOnce Makes It Much Easier to Deploy It works like this: developers "publish" a Windows Forms application to an IIS server and specify any prerequisites, assemblies to include, and deployment preferences. End users can then go to a Web page or hyperlink and initiate installation or update from the published location. Subsequently, each time the application starts it contacts the IIS server to make sure that it has the latest version of the program. There are a number of nice options and features built into ClickOnce. After the application has been installed the first time, a start-menu shortcut can be made available. Applications that are capable of working offline can be configured to operate without being connected to the network. Control of which software version updates are applied can be controlled centrally or left up to the end user. Also, parameters can be passed from the IIS server link through to the Windows Forms application.
Years of Legacy Web Applications Can't Be Replaced All at Once Much of money and time has gone into existing Web applications built using ASP/COM, and more recently, ASP.NET technologies. These applications have been finely tuned over the years and frequently serve as the primary interface for business-critical software systems. In many cases, the performance and reliability of these applications is more than acceptable, so there is no justification for replacing them. When planning the construction of a new software system or user interface however, it is preferable to utilize new technology. There are many advantages to migrating to a .NET 2.0 and Windows Forms technology base. .NET has a proven track record of reducing development times and costs, and it has been improved even more for performance, scalability, and reliability with version 2.0. In addition, this technology has a large user community and will be supported for many years to come.
The Problem: Launching Windows Applications from the Web Is Not Easy Anyone who has tried to configure a Web site to communicate with a client's machine knows that the security is very tight. It's not possible to execute code on a client workstation from a Web application without physically modifying the application security settings on the client machine to specifically allow it. Moreover, it is even more difficult to configure a Web application to interact with an instance of an application already running on the client machine. The client application will be running in a separate process than the client-side portion of the Web application. It is, of course, very desirable to strictly control the access that Web-based programs can have on a client machine. Bypassing this security obviously introduces a significant degree of risk, and while it can be mitigated by signing assemblies and only allowing specific code to execute, there is still a loosening of security rules that should be avoided in most cases. Basically, while it may be acceptable for a few specific implementations, once loosening of security becomes the general architectural rule for enterprise development, the chances increase that security holes will be introduced.
The Solution
Create the Windows Forms Application The code of this form only needs two modifications. First, create a private member to hold the string array of parameters that will come in from ClickOnce. private string[] _parmArray; Second, create an overload of the Form.Activate() method that accepts a string array as a parameter. This will be used by the application to send the parameters it receives from ClickOnce up to the form. Listing 1 shows the code for this Activate method overload. It simply calls Activate() on the base class, copies the parameter to the local _parmArray variable, and binds the ListBox to _parmArray.
Program Modifications public class Program : WindowsFormsApplicationBase Next, modify the Main() method to handle the parameters coming in from ClickOnce. ClickOnce URIs that use HTTP have the following basic format: "http://<published location>/<application name>.application," where <published location> represents the location of a directory served by IIS. Parameters can be appended to the ClickOnce URI using the same syntax as HTML querystrings. An example of a "ClickOnce" URI with parameters might look like this: http://MyServer/MyApp.application?parameter1¶meter2 Listing 2 shows the modified static void Main method. It extracts the parameters by retrieving the URI that was used to launch the application, splitting the query portion of the URI on the "&" symbol into a string array, and passing this array along to a new instance of Program. From this point forward, parameters are in a string array and are treated as command-line parameters. Page 1 of 2 next page »
MICROSOFT .NET LATEST STORIES
SUBSCRIBE TO THE WORLD'S MOST POWERFUL NEWSLETTERS SUBSCRIBE TO OUR RSS FEEDS & GET YOUR SYS-CON NEWS LIVE!
|
SYS-CON FEATURED WHITEPAPERS MOST READ THIS WEEK BREAKING NEWS FROM THE WIRES
|
||||||||||||||||||||||||||||||||||||