views:

1763

answers:

8

I have a problem where a Web Application needs to (after interaction from the user via Javascript)
   1) open a Windows Forms Application
   2) send a parameter to the app (e.g. an ID)

Correspondingly, the Windows Forms Application should be able to
   1) send parameters back to the Web Application (updating the URL is ok)
   2) open the Web App in a new brower, if it does not exist
If many browser windows are open it's important that the correct one is updated.

Windows Forms Application is in ASP.NET
Browser is IE6+
The applications are controlled and internal for a specific organisation so it's not a question of launching a custom app.

Question A) Is this possible?
Question B) How do I send parameters to an open Windows Forms Application from a Web App?
Question C) If updating the Web App, how do I make sure the right browser is targeted?

A: 

No I don't think it's possible.
Think of viruses/trojans/spyware. If it were possible to launch an application from a mere HTML page, it would be very easy to install malware.
Browsers are designed to prevent you from doing that.

Sklivvz
Sorry, I will clearify the question. This is all in a secure, corporate environment. The client app is launched today so that is not the problem - it's the interaction that creates problem
Bruce
Then embed the browser inside the Winforms application
Sklivvz
Yup, that came up as an idea but we're not allowed such major modifications on the Winform app. Thanks though!
Bruce
A: 

You could use clickonce to deploy and start the forms app - this should take care of sending the parameter to the app.

1800 INFORMATION
From what I understand this would only help during launching of the app, not communicating with it once it's running?
Bruce
+4  A: 

What you're asking for is possible but seems awkward.

Trying to call an application from a web page is not something you could do due to security considerations. You could however make a desktop application which would be associated with a certain type of files and then use content-type on the web page to make sure that your app is called when a URL with this type is opened. It would be similar to the way MS Office handles .doc or .xls documents or the Media Player opens the .mp3 or .wmv files.

The second part (opening a particular web page from your application) is easier. As you should know the address of your web page create a URL string with the parameters you want and open it in default browser (there are plenty of examples on how to do that, a sample is below).

System.Diagnostics.Process.Start("http://example.com?key=value");

If you want to update the page in the already opened browser or use a browser of your choice (i.e. always IE6 instead of Opera or Chrome) then you'll have to do some homework but it's still quite easy.

Ilya Kochetov
Opening the client app from the browser should be the easy part, it's communicating with it after it's opened that riddles me.Also, opening a browser from the client app is a no-brainer but if it's already opened - how do I target right one to update?
Bruce
+1  A: 

Check out http://msdn.microsoft.com/en-us/library/8c6yea83(VS.85).aspx

Using VBScript in your Web Page you can call an open Windows Forms application and send keys to it.

This only works on IE though and you need to adjust the security settings to allow ActiveX.

Yes, this is somewhat in the right direction. Will look into it! Thanks
Bruce
+1  A: 

Have a look into "registered protocols" (for example here and here). I know Skype does this to make outward phone calls from a web page. But probably some changes will be needed in the win application to intercept the parameters from the url.
I haven't tried this but it should be possible

dDejan
This seems to point in the right direction! Thanks!
Bruce
A: 

While this may not perfectly fit with your application, what about using a web service and the form?

Also, you can pass parameters to ensure IE6, not Firefox opens.

System.Diagnostics.Process.Start("c:\ie6\ie6.exe http://www.example.com/mypage");
Kevin Lamb
A: 

Ok, so I actually found a clue to the web -> winform part.

The following code was handed to me from an web application that sends a parameter to a winform app. I assume this solution has some security factors in play (such as allowing running VBScript (and ActiveX?) in the webpage. That's ok for me though.

The code:

<script type="text/vbscript" language="vbscript">
<!--
Function OpenWinformApp(chSocialSecurityNumber)
Dim oWinformAppWebStart
Set oWinformAppWebStart = CreateObject("WinformAppWebStart.CWinformAppWebStart")
oWinformAppWebStart.OpenPersonForm CStr(chSocialSecurityNumber)
End Function
-->
</script>

Bruce