YOUR FEEDBACK
Adobe Flex 2 - Answering Tough Questions About Enterprise Development
A Correct Person wrote: Denis Roebrt commented on the 21 Aug 2006 "Tough Que...

SYS-CON.TV
TOP MICROSOFT .NET LINKS


Making Windows Forms Work with Legacy Web Applications
A pattern that uses .NET 2.0 and ClickOnce

Digg This!

Page 2 of 2   « previous page

Next, the application needs to be modified to pass the parameters along to ExampleForm. Listing 3 shows how this can be done for new instances by overriding the OnCreateMainForm() method in the base class. This method copies the command-line arguments to a local variable, creates a new ExampleForm, then calls the Activate method overload that we added in order to pass the parameters to it.

If the application is already running, however, OnCreateMainForm() won't be called, so another method is required. When Windows attempts to start an application that is already running, an event named "StartupNextInstance" fires. Listing 4 is the code for a custom event handler that does essentially the same thing as the OnCreateMain-Form() override, but for a running application.

Finally, Listing 5 shows the default constructor for Program, where the StartupNextInstance event handler is wired up, and where we set Program to run as one instance. If you don't set the "IsSingleInstance" property to "True," the program will launch a new form each time it is activated. This completes the demo application.

ClickOnce Configuration
Next, the application needs to be configured for ClickOnce publishing. Right click on the project in the Solution Explorer pane and choose Properties. Select the Publish tab and click the Options button. Click on the checkbox labeled, "Allow URL parameters to be passed to application." That's all that needs to be done - all other ClickOnce options can be left at their default settings.

Publishing the Application
In Visual Studio, click on the link labeled "Publish ClickOnceWindowsFormsApplication" in the Build menu. If you have IIS running on your machine, you can publish to the default localhost. If not, you will need to publish the application to an IIS server. After choosing the location, click the button labeled "Next >."

The next form lets you choose whether or not a start menu shortcut will be created for this application. It does not matter for our purposes here, the example will work either way. Click "Next >" to the confirmation screen, then "Finish" to publish the application to the server.

Web Application Links
The last piece is to create the hyperlinks in your Web page or Web application. This should be fairly straightforward. Create a simple HTML page with two anchors in it, one to pass a single parameter and another to pass two parameters. Listing 6 shows the code for the HTML file. This particular HTML file can be run in any browser, and does not need to be served up by IIS.

Now click on the first hyperlink and see what happens. ClickOnce should prompt you to download and install the application. When installation is complete, the form will open displaying the parameter values from the hyperlink If you switch back to the HTML page in the browser and click on the other hyperlink, a ClickOnce window will display briefly, checking for new updates, then the Windows Form application will gain focus and display the parameter values from the second querystring.

Conclusion
Naturally, this process is extremely simplified. It does not address the important issues of authentication and authorization, for example, which need to be addressed for any application using this pattern. Also, this solution provides only one-way communication, with messages originating at the Web application and being received by the Windows Forms application. If the Web application needs to respond to changes, refreshes will need to be initiated.

However, this pattern provides a way to launch or refresh a Windows Forms application running on a user's desktop with data from a legacy Web application, something that has been extremely difficult and risky in the past. Expanding on this pattern, systems can be engineered so that complex run-time data is transmitted quickly from Web to windows, thereby integrating the applications and increasing user productivity.

Resources


Page 2 of 2   « previous page

About Guy Starbuck
Guy Starbuck is a senior application architect for Stericycle, Inc. He has been working in the software industry for over nine years. Guy lives in Arlington Heights, IL with his wife and son.

Neil wrote: I see what you're doing here. But does it work that if you pass parameters to the second instance via the URI they are then loaded by the first instance? I'm unable to replicate in VB if they are. I can't figure out how to do the Program(): Base()
read & respond »
Mosaic wrote: Great article - thanks!
read & respond »
MICROSOFT .NET LATEST STORIES
Icahn Moves To Force Microsoft & Yahoo Together
Corporate raider Carl Icahn started his proxy fight for control of Yahoo this morning, beginning with the classic Icahn opening, the letter of reproach to the Yahoo board telling them they have acted 'irrationally and lost the faith of shareholders and Microsoft.'
IBM, Microsoft & Google Eras of Computing
By now it is conventional wisdom to say that there was an IBM Era of computing, then a Microsoft Era, and now we are in the Google Era. In this post, I will explain why Microsoft was not the 'next IBM' and why Google is not the 'next Microsoft' - there are significant qualitative diffe
Book Review: ASP.NET 2.0
ASP.NET developers are bored with traditional books that outline concepts in a lengthy way. These books are good if you like to learn the features in a detailed manner. However, by the time the book is read, a new version will be released. Hence, many learners including myself prefer s
3rd International Virtualization Conference & Expo: Themes & Topics
From Application Virtualization to Xen, a round-up of the virtualization themes & topics being discussed in NYC June 23-24, 2008 by the world-class speaker faculty at the 3rd International Virtualization Conference & Expo being held by SYS-CON Events in The Roosevelt Hotel, in midtown
"RIA" vs "Rich Client Platform": The Term Is Now Up for Debate
'RIA' is slowly fading in terms of its definition. When I first started the RIA Evangelism role in Microsoft, I had this nagging feeling that the term RIA was just all over the place. Depending on which technology you are backing and which stream of alliance you uphold, the truth is th
SUBSCRIBE TO THE WORLD'S MOST POWERFUL NEWSLETTERS
SUBSCRIBE TO OUR RSS FEEDS & GET YOUR SYS-CON NEWS LIVE!
Click to Add our RSS Feeds to the Service of Your Choice:
Google Reader or Homepage Add to My Yahoo! Subscribe with Bloglines Subscribe in NewsGator Online
myFeedster Add to My AOL Subscribe in Rojo Add 'Hugg' to Newsburst from CNET News.com Kinja Digest View Additional SYS-CON Feeds
Publish Your Article! Please send it to editorial(at)sys-con.com!

Advertise on this site! Contact advertising(at)sys-con.com! 201 802-3021

SYS-CON FEATURED WHITEPAPERS

ADS BY GOOGLE
BREAKING NEWS FROM THE WIRES
Strangeloop Networks Selected for Red Herring 100 North America 2008
Strangeloop Networks (TM) Inc., a leading provider of solutions that accelerate dynamic web