Web应用程序如何与客户端硬件对话? [英] How a web app can talk to client hardware?

查看:344
本文介绍了Web应用程序如何与客户端硬件对话?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

世界您好! :)

我有一种情况,我想不出什么是解决该问题的最干净的"方法,谢谢您事先提出的​​任何想法.

问题:
我需要构建一个Web应用程序,其中客户端窗体需要从C#DLL驱动的硬件中获取输入.其中一些DLL具有需要激活的应用程序/会话范围.

解决方法:
-最简单的方法是使用隐藏框架,该框架使用JavaScript ActiveXObject()控制硬件DLL的活动和读数.
-另一个选择是以某种方式使我的Hw控制器成为IE浏览器的附加组件",并从JavaScript调用它.我认为这可以通过浏览器帮助器对象以及通过以下方式在JavaScript中进行调用来实现:navigator.MyController.
-进行后台服务以启动/停止硬件通信,并将控制器从JavaScript中分离出来.

有帮助/意见吗?
请避免不是推荐方法的烈火大战. :)

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. :)

推荐答案

您需要知道的第一件事:DLL没有会话.您应该更好地讨论程序集和类库,因为.NET中的"DLL"只是扩展名",是文件名的一部分,仅此而已.它可以是任何东西,甚至可以将.EXE文件用作库:引用,加载等.

.NET类库的任何对象的作用域和生存期完全由加载库的过程(更确切地说,由应用程序域)定义,请参见System.AppDomain
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


不是推荐的解决方案! ;)

但是说真的,我认为不是.如果没有安装ActiveX并允许他们在访问您的网站时运行它,就无法与客户端计算机上的硬件通信,那么为什么不让他们安装WinForms(或WPF)桌面应用程序来管理硬件呢?使事物基于浏览器的通常原因是避免用户安装任何东西,在这种情况下这是不可能的–您已经在使他们安装ActiveX和与硬件通信的程序集.如果您需要进行同步,则该应用可以与您的服务器(通过HTTP(S)或其他协议)进行通信.

正如其他一些人提到的那样,从Web应用程序运行持久通信很困难,因为一旦用户离开您的页面,页面中的所有内容都会丢失.您必须通过存储某种会话令牌(不要与服务器端Web会话混淆)并在加载新页面时重新连接来伪造它.

您能解释为什么要使用Web应用程序吗?在技​​术上可以(可能)按照您的意愿进行操作,但这绝对是一个方钉和一个圆孔,并且我目前不了解您为什么选择这条路线.
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.


恢复旧帖子以使该主题具有最终状态...

因此,在使用技术之后,我们能够开发一个小型框架来满足我们的需求.我们必须混合使用:IE9,ActiveX,BHO,C#,JavaScript,JSF2和一些技巧,以便根据客户要求来实现所有这些功能.

最终,它被确定为过于不可靠和不可维护.现在他们很高兴我们能使用完整的.Net表单,该表单实现了Web服务来管理部分业务逻辑.
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.


这篇关于Web应用程序如何与客户端硬件对话?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆