Click here to Skip to main content
15,891,136 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hello world! :)

I have a situation which I can't figure what it will be the "cleanest" way to solve it Thanks for any ideas in advance.

Problem:
I need to build a web application in which the client forms need to get input from hardware that is driven by C# DLLs. Some of these DLLs have an application / session scope for which they need to be active.

Workarounds:
- The easiest way will be to use a hidden-frame which uses JavaScript ActiveXObject() to control the Hw DLL activity and readings.
- Another option will be to somehow make my Hw controller as an IE browser "addon" and call it from JavaScript. I think this is doable through Browser Helper Objects and some how make calls in JavaScript as: navigator.MyController.
- Make a background service which start / stop the Hw communication and separate the controller to be what is call from JavaScript.

Any help / opinions?
Please avoid a flame war of not being a recommend approach. :)
Posted
Updated 18-Apr-11 12:09pm
v2

First thing you need to know: DLL's have no sessions. You should better talk about Assemblies and class libraries, as "DLL" in .NET is just "extension", a part of file name, no more; it can be anything, you can even use .EXE file as a library: reference it, load it, etc.

The scope and life time of any objects of .NET class library is totally defined by the process where the library is loaded, more exactly, by the Application Domain, See System.AppDomain, http://msdn.microsoft.com/en-us/library/system.appdomain.aspx[^].

Keeping it in mind, I trust you can figure out your remaining questions by yourself.

Good luck,
—SA
 
Share this answer
 
Comments
hyperplus 18-Apr-11 16:40pm    
SAKryukov, thanks for the prompt response. I have read some about this topic, but a little more pointers will be appreciated. Below is what I understand how I could use this and a little more detail about the problem.

Possible scenario flow:
When user enters the page to start the "Test Routine" a "calibration" process is started with the hardware which needs to keep the communication active. When calibration is complete, the user will move to the next page which is to get "Actual Readings". During this flow I can't loose my active communication...

What I understand can be done:
Create an AppDomain which will host the active communication. Get the active instance from this AppDomain in the next page.

Questions?
Is this what you had in mind? :)
So this means I have to startup my AppDomain Main() to be running in the background to perform this activities?
I don't think I can just use the IE AppDomain to plug my functionality in.

Thanks for any advise
Sergey Alexandrovich Kryukov 18-Apr-11 16:53pm    
No, you usually do not have to create AppDomain, you already have one, the default one, this is enough. I mentioned AppDomain to make my statement formally correct, because if you ***would*** have extra domain, your scope in question could be less then a scope of whole process. Basically, you need to create AppDomain for complete data isolation; one convincing reason is re-loadable plug-in Assembly, because if is not possible to unload Assembly from the process, you can unload only a whole domain. If you need a design like that, I'll give you the reference. I don't see where you need an extra domain right now.

You major problem is that a lifetime in you process is limited by a single HTTP request. This is a major limitation of ASP.NET stemmed from the state-less nature of HTTP. As a result, you need to consider a process of the next request as a completely different process. To keep application integrity, you need to persist the all the states you need in a next instance of the process after new request/post-back. That should be a basis from your session support.

--SA
hyperplus 18-Apr-11 17:12pm    
Thanks for your help. This is not a trivial problem for me about how to address the requirements. I am getting a little lost in trying to get your idea...

What will be considered the default AppDomain? The one in the web server or the one running the browser? Or actually both? I think it will be the one in the browser, but I will not have access to play there. That's why I was thinking I need my own AppDomain.

What will I really gain by persisting the Hw object & connection? From my understanding, this will serialize the object instance, send it to the server and restore it back in the client when the next page is loaded. Am I missing something?

Another quick note: The web app is not .Net oriented, and actually it will use a Websphere server with Facelets.
Sergey Alexandrovich Kryukov 18-Apr-11 17:29pm    
No, I did not mean browser. Yes, browser is another one, pretty much irrelevant as it reflects the session as it understood at the server. I mean each time your Web application gets a HTTP request your APS.NET code-behind code is run over again (previous instance of the process gets terminated, the new one started). From your standpoint, you do not communicate between the instances through memory or other objects, only through persistence.

--SA
Sergey Alexandrovich Kryukov 18-Apr-11 17:31pm    
If you Web application is not .NET oriented, I have not idea what hosts/loads your .NET code (you should have explained that from the very beginning), but my general considerations remain valid.
I was keeping in mind a normal ASP.NET application. I'm not even familiar with WebSphere (but have some minor experience with other Server-side models).
--SA
Not the recommended solution! ;)

But seriously, I don't think it is. You can't communicate with hardware on the client machine without them installing an ActiveX and permitting you to run it when they visit your website, so why not have them install a WinForms (or WPF) desktop app to manage the hardware instead? The usual reason to make things browser-based is to avoid the user having to install anything, which isn't possible in this case – you are already making them install an ActiveX and the assemblies which talk to the hardware. That app can talk to your server (via HTTP(S) or other protocols) if you need to synchronise things.

As some others have mentioned, running a persistent communication from a web app is hard because as soon as the user navigates off your page, everything within it is lost. You would have to fake it by storing some sort of session token (not to be confused with the server-side web session) and reconnecting when the new page is loaded.

Can you explain why you want to use a web application? It is (probably) technically possible to do what you say you want, but it is definitely a square peg and a round hole, and I don't currently understand why you are taking that route.
 
Share this answer
 
Comments
hyperplus 19-Apr-11 20:11pm    
Bob, thanks for the input. I totally agree with the bad approach to the problem, but is the customers requirement. We are still trying to change this, but meanwhile we need to move forward.

That's why the only way is to use IE and ActiveX to access the hardware. This will be an intranet
application so we are ok with some other major concerns that this approach brings. At the end seems I am back to how will approach this?

I guess either frames or IE BHO implementations.
BobJanova 20-Apr-11 13:12pm    
Point the client at my comment? ;) Because yeah this is a terrible solution.

Are you in charge of the C# DLLs that interface to the hardware directly. Because you are going to have to maintain sessions in them and deal with all the issues of people not browsing 'properly'.
Reviving an old post to give a final status to this subject...

So after playing with technologies, we were able to develop a small framework which will accomplish our needs. We had to mix: IE9, ActiveX, BHO, C#, JavaScript, JSF2, and a couples of tricks to get all this working based on customer requirements.

Finally it was decided it will be too unreliable and unmaintainable. And now they are happy we are going full .Net forms which implements web services to manage part of the business logic.
 
Share this answer
 
Comments
yesotaso 10-Jun-11 13:40pm    
Well it seems quite a feat even to get those work together do something :) Anyway, gratz and good luck.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900