简体   繁体   English

.net Winform和Webform之间的通信

[英]Communication between .net winform and webform

I need to make a webform communicate with a winform and back to the webform. 我需要使一个Web窗体与Winform通信并返回到该Web窗体。 The reason for this is it exists a webform software already made, and now it's needed the behavior of a .net component only available for winforms. 原因是它已经存在一个已经制作的Webform软件,现在需要仅可用于Winforms的.net组件的行为。 We've tried going with Process.Start and shell.execute but with this approach the software hangs or it takes too long to respond. 我们尝试使用Process.Start和shell.execute,但是使用这种方法,软件会挂起,或者响应时间太长。 The webform also needs to be called from client pcs in the network, I think this adds another problem due to the non possibility of calling the execution of a file from a webform remotelly, but I dont know much about this technical issue 还需要从网络中的客户端PC调用Webform,我认为这又增加了另一个问题,因为不可能从WebForm远程调用文件的执行,但是我对该技术问题知之甚少

we've read some articles about embedding a winform in a webform, sending data from a winform to a webform, etc. and we would like to know what's the recommend approach (if there is any) for handdling a situation like this. 我们已经阅读了一些有关将winform嵌入Web表单,将数据从Winform发送到Web表单等的文章,并且我们想知道处理这种情况的推荐方法(如果有)。

If you have access to the source code for the WinForms application, then your best approach is to extract the code that you need from there and incorporate it directly into your WebForms application. 如果您有权访问WinForms应用程序的源代码,那么最好的方法是从那里提取所需的代码,并将其直接合并到WebForms应用程序中。

If this code needs to be used by both the WinForms and your WebForms application, then you should instead refactor the code that will be shared by both into a separate class library (DLL), which is then used by both applications. 如果WinForms和WebForms应用程序都需要使用此代码,则应将两者共享的代码重构为一个单独的类库(DLL),然后由两个应用程序使用。

If you only have the EXE of the windows application, and it is a .Net application, you can use Reflection to create and use objects defined there. 如果您只有Windows应用程序的EXE,并且它是.Net应用程序,则可以使用Reflection创建并使用在那里定义的对象。

If it's not a .Net EXE, goodbye and thanks for all the fish (unless it's COM, in which case goodbye and thanks for all the fish). 如果不是.Net EXE,请再见,感谢所有的鱼(除非是COM,在这种情况下,再见,感谢所有的鱼)。

Update: I have never tried this, and I do not recommend it, but I'm assuming that you basically want to be able to use a windows-forms based visual component in a web application (ie you want this thing to show up in their browser). 更新:我从未尝试过,并且推荐这样 ,但是我假设您基本上希望能够在Web应用程序中使用基于Windows窗体的可视组件(即,您希望此内容显示在他们的浏览器)。

You may be able to rebuild each Form in the original WinForms project as an ActiveX control that is then situated on a web page. 您可以将原始WinForms项目中的每个Form重建为一个ActiveX控件,然后将其放置在网页上。 This link describes how to create a basic ActiveX control in .Net: 此链接描述了如何在.Net中创建基本的ActiveX控件:

http://www.codeproject.com/KB/cs/CreateActiveXDotNet.aspx http://www.codeproject.com/KB/cs/CreateActiveXDotNet.aspx

I have no idea about browser support for ActiveX controls these days (I know there's some still), and this approach would certainly not work on non-Windows OSes. 最近,我不知道浏览器是否支持ActiveX控件(我知道仍然有一些支持),并且这种方法在非Windows操作系统上肯定行不通。 Also, you have to deal with deploying and installing the visual component on each client machine (and you'd need to check your licensing agreement for this control - it almost certainly will specifically prohibit this type of use). 此外,您还必须处理在每台客户端计算机上部署和安装可视组件的问题(并且您需要检查许可协议才能获得此控件-几乎可以肯定,它将特别禁止这种类型的使用)。

In theory, though, this would work. 从理论上讲,这是可行的。 An ActiveX control can more or less do or use anything that a regular Form can (subject to permissions etc.). ActiveX控件可以或多或少地执行或使用常规Form可以执行的任何操作(取决于权限等)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM