How to interact between Web App and Windows Form Application - asp.net

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?

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.

PokeIn library connects you desktop application to your web application in real time/per user. Moreover, due to its reverse ajax state management, you could consider both of your applications as one.

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.

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

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.

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

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");

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>

Related

VB application invoking & directing requests to web browser

We've an existing application developed in VB 6. There are 6 - 8 modules available. In main screen, a separate button is available for each module, which on click will load the respective modules. We're in the process of migrating this to a web-enabled system and identified to go with Java-based solution.
Now instead of completely developing and migrating to Java platform, we're doing a technical feasibility study of migrating module-wise. That is, on click of 'Module 1', for example, will open up a browser instead of existing VB application forms and all subsequent handling/processing/loading/saving will be handled by the web-based Java application, which actually runs on a web/app server. Slowly this will be migrated for other modules also.
My question is, is this technically possible/feasible? That is, can we open up a browser on click of a button and direct all subsequent requests, sessions, cookies to the Java application running on web/app server. Any pointers/suggestions/thoughts towards this are really appreciated.
NOTE: I heard about WinINet API from my friends which enables to interact with HTTP protocols.
If you are moving to the "poor client" (Web) model then your back end will be creating 100% of the user interface as Web pages.
In such a case your existing rich client needs to be dumbed down. There is no point in trying to request the HTML from the server and reinterpreting it into a rich user interface written in VB6.
Thus you don't need to worry about the WinInet API (which you wouldn't need anyway since from Win2K onward you have at least 3 very nice wrapper ActiveX controls and classes at your disposal: the Internet Transfer Control, the XmlHttpRequest class, and the WinHttpRequest class).
No, in your case you will probably be stuck with replacing your "modules" (???) which probably means Forms (?) by a Form hosting a WebBrowser control.
However it will be clumsy to integrate what goes on in there with your other "modules." If that's needed you're going to probably need to spelunk the WebBrowser DOM to fish out data, inject data, etc.
Ideally you'd be moving to a Web Service model instead of a Web model. This opens a world of front end possibilities (Web, mobile, rich client) without the need for multiple back ends and is quite usable in VB6. Things have even gotten easier over time as SOAP is abandoned in favor of simpler, loosely-coupled RESTful Web Services.
What you have described is feasible to a degree, but when you start adding requirements like session cookie control it might get ugly. You may end up needing two logons in your program, one for the old/existing parts and another for the browser-based parts.
You might be better off just letting part go over to a browser and strip parts out of the old app and make people run both side by side.

ASP.Net MVC4 self-hosted API on same port as website

Dear developer friends,
I have developed a self-hosted API in ASP.Net MVC4 (e.g. http://blogs.msdn.com/b/henrikn/archive/2012/03/01/file-upload-and-asp-net-web-api.aspx), because I needed a solution where I could upload super large files. This works smoothly.
Now I want to upload files to my newly written API through the Bluimp JQuery Upload component.
This works fine, except for some small flaws:
- the progress-bar is not showing
- JQuery raises an error: Unsafe JavaScript attempt to access frame with URL...
It seems clear that this error is raised, because my API runs on another port than the web application, and ajax calls cannot be made over cross domains / ports.
I have already added the forceIframeTransport: true parameter to the fileupload component call. This does some good - without it I cannot upload files at all (because the component tries to upload with an ajax call).
So.. I figured that if there's some way to run my self hosted API on the same port as my web-application (with explicitly defined routes), my world will be happy and shiny again. However.. I'm not quite sure whether this is possible at all..
Unfortunately a proxy from my ASP.Net application will not help me here, as I wrote the API to avoid the IIS limitations (regarding maximum upload size). Using my self hosted API as proxy might to the job, but I think this is a bit.. overkill?
Anyone? Thanks in advance!
Yahoo! Solved it!
var config = new HttpSelfHostConfiguration("http://localhost:49302/api");
In other words - the web api ONLY works when the url starts with /api. All other requests are picked up by my MVC4 web application. But they run on the same port.
So to answer my question: yes it's possible. Just add a root directory.

Access qt application as web page

I have a qt main-window application from which several dialogs are accessed.
I implemented the server and client versions of the application using tcp/ip using c socket programming.
But now I have been told to make the application accessible to any web browser after username and password have been given using QHttp or any appropriate class.
I'm a beginner and have no idea of implementing this. Could anyone give some tips or examples.
I'm using qt 4.6.2
I'm not sure I understand you. You have a Qt main window which contains some widgets arranged in a GUI. You want those same widgets to be accessible inside a web browser? Then you need to re-create all your GUI code in HTML, CSS and JS.
Your Qt app can use QHttp to listen for incoming client connections. When one of those comes, you reply with a webpage (written in HTML, CSS, JS). When this webpage is received by the user, his browser will display it. When the user interacts with the webpage, you'll probably want to send some data back to the Qt server eventually. You can do this either via form posting or via XMLHttpRequest.
You should know client-side web development is not that simple. Even when you know your languages, there's lots of things to learn about browser compatibility, security, accessiblity, JS app architecture, etc.
You want to make your application into an Http server. Here is an example using Qt to get you started:
http://doc.qt.nokia.com/solutions/4/qtservice/qtservice-example-server.html
As Stefan notes, this means putting your GUI into HTML/CSS/JS and more.

How to get list of drives on local system using ASP.Net

I am going to develope a module in ASP.Net. In this module I want to get the list of drives of the local system where this page is displaying. I have already tring with System.IO.... etc. but it gives me the server drives.
I want to get the list of LOCAL drive where page is displaying on server drives.
Thank you.
Do you mean the client's computer's drives?
That is not possible.
EDIT: However, it is possible with ActiveX or a browser plug in.
This absolutely cannot be done with neither server-side ASP.NET, nor with client-side JavaScript. You can try writing an ActiveX "control" (or how are these called?) or Java applet.
Fortunately you can not do that.
This is impossible, since your ASP.Net code runs on the server. The client only sees the rendered page (HTML and javascript).
Remember: your C# or VB.Net code runs on the server for the explicit purpose of sending html/javascript to the client browser. It does not get to peek directly at the "local" system, and the only thing the "local" system knows about is the html/javascript rendered on the server. That's just how the web works.
Furthermore, javascript runs in a sandbox that does not include any way to enumerate the local drives. This is by design.
So the only way to do this is via plug-in like flash, silverlight, or activex.
You can write a .NET control which is downloaded from your website to the clients' PC and looks at the drives there. As this could be abused (you could steal the users' files) you will have to convince the user to download the control in the first place. Look here for more info:
ClickOnce Deployment overview

How to capture image from client webcam in asp.net

I am working on an ASP.Net application and I want users to be able to take a picture with their local webcam and then upload it to the server.
I can, of course, rely on users doing this manually via their locally installed software, save the image as a file and do a normal file upload. However, what I really want to do is incorporate it all into a UI in the browser.
I know this means accessing local resources so do I need an ActiveX control or Silverlight or is there something I could do in Javascript for example?
This is initially intended for an Intranet app so I can have control of the client's environemnt, including stipulating the browser etc, which means I can use an ActiveX control if I have to. However, it would be nice if I could write this in a generic way so it could be used in an internet app generally (happy to stipulate that it only works on Windows clients but would be good to get it to work in FireFox).
Thanks.
The only acceptable and universal way to this for now is Flash/Flex application. Flash player presets literally in every browser in the world and all of them has such capability.
VideoCap Pro is quite popular, and it offers an ActiveX version, have you checked it out?
This sounds very suspicious to me. You realize the nefarious applications this could be applied to, right? A web page that when a user browses to it, unknownst to them, their webcam snaps a pic of them. ... I don't like it.
You could use the Nimbb API to do the webcam video recording inside a browser.
It is possible to get the image from client webcam in asp.net, you have to install the Silverlight 4 with Visual Studio 2010:
Go to following link:
http://wildermuth.com/2009/11/23/Taking_a_WebCam_Photo_with_Silverlight

Resources