简体   繁体   English

如何通过局域网正确执行C#文件?

[英]How to properly execute C# file over local network?

Overview 总览

C# File - Users PC C#文件-用户PC
PHP Server - Hosts Webpages for application PHP服务器-托管应用程序的网页

Server and Users PC on local network 本地网络上的服务器和用户PC

I have ac# file that reads weight from a USB scale. 我有一个ac#文件,可从USB秤读取重量。 How would I trigger this file to run so it feeds into my program. 我将如何触发该文件运行,以便将其输入到程序中。 The problem is I am using PHP to host our webpage/application so its not running client side and the scale is not hooked up to the server but to the clients PC. 问题是我正在使用PHP来托管我们的网页/应用程序,因此它不在客户端运行,并且扩展规模并未连接到服务器,而是连接到了客户端PC。

The C# script would have to be on the clients in order to read the scale so how would I trigger this to happen? C#脚本必须在客户端上才能读取刻度,那么如何触发这种情况呢?

Is this even possible and if not what would be a better way? 这是否可能,如果没有,哪种更好的方法?


Important Edit 重要编辑
I was able to run the Scale Script (C#) when I wanted by having PHP and C# use TCP sockets. 我希望通过使PHP和C#使用TCP套接字来运行Scale Script(C#)。

The C# would listen for PHP to send something and when it did it would read the scale and send this information back to PHP becuase PHP was listening for a response. C#会侦听PHP发送的信息,而C#会读取秤并将此信息发送回PHP,因为PHP正在侦听响应。 Mixed in with a little Ajax and it updates in the web browser. 混入了一点Ajax,并在Web浏览器中更新。

Gave Chris Credit because he was the most helpful with answering my questions 给克里斯·克里斯多夫(Chris Credit),因为他在回答我的问题方面最有帮助

It sounds like what you really want is for the client application to submit the data to the website itself, and the most suitable approach is probably to expose a web service from your server. 听起来,您真正想要的是客户端应用程序将数据提交到网站本身,而最合适的方法可能是从服务器公开Web服务。

This service should accept weight data, along with some sort of customer key or whatever, to correlate the records correctly on the server side. 该服务应接受重量数据以及某种客户密钥或其他任何内容,以在服务器端正确关联记录。 I've never created a web service in PHP personally, so I can't give any advice on the implementation of that, but it is fairly trivial to hook a C# client app up to a web service once you've exposed its metadata (assuming you use SOAP). 我从来没有亲自用PHP创建过Web服务,因此我无法提供有关该实现的任何建议,但是一旦公开了C#客户端应用程序的元数据(假设您使用SOAP)。

C# isn't a scripting language, it's a language that compiles into executable binaries or libraries. C#不是脚本语言,而是一种可编译为可执行二进制文件或库的语言。 You won't be able to execute C# code on the client's computer via a website because C# code needs to be compiled before it can run. 您将无法通过网站在客户端计算机上执行C#代码,因为C#代码需要先编译才能运行。

Presumably what you really want is for your compiled C# binary to be executed on the client's machine via your website. 大概您真正想要的是通过您的网站在客户端计算机上执行已编译的C#二进制文件。 You won't be able to easily do that. 您将无法轻松做到这一点。 There are a lot of security measures in place to prevent browsers from running programs on your computer. 有很多安全措施可以防止浏览器在计算机上运行程序。 There may be ways to hack around these security measures by using plugins (such as ActiveX), but it's not something that will be a one-liner. 可以通过使用插件(例如ActiveX)来破解这些安全措施,但这并不是一成不变的。

Edit: I think you need to step back and think about what you're trying to do in a broad sense. 编辑:我认为您需要退后一步,从广义上考虑您要尝试做的事情。 You're trying to create a website that can read information from a user's USB port. 您正在尝试创建一个可以从用户的USB端口读取信息的网站。 This is the type of thing that browsers are designed to prevent , and for good reason. 这是浏览器旨在防止的事情,这是有充分理由的。 I wouldn't want random websites to be able to access peripheral hardware without my explicit permission. 未经我的明确许可,我不希望随机网站能够访问外围硬件。 If you want this website to function the way you're expecting, you're going to have to seriously think about the security implications. 如果您希望该网站以您期望的方式运行,那么您将必须认真考虑安全隐患。 You'll need some kind of client-side code (ActiveX, Silverlight, ...), and the user will need to explicitly give permission to for this all to happen. 您将需要某种客户端代码(ActiveX,Silverlight等),并且用户将需要明确地授予权限以使所有这些事情发生。 It won't be easy, and it won't be automatic. 这不会容易,也不会自动。 And I'm damn glad that's true. 我真的很高兴那是真的。

you can't start C# application from a web page in a way that'll work in every browser every time. 您不能以一种每次都能在每种浏览器中都能使用的方式从网页启动C#应用程序。 BUT, you can have some workarounds: 但是,您可以采用一些解决方法:

  • Use ActiveX component that read the data in the client and upload it to the server. 使用ActiveX组件读取客户端中的数据并将其上载到服务器。 the biggest cons is that it'll only work in Internet Explorer 最大的缺点是只能在Internet Explorer中使用
  • use Silverlight client application that runs on elevated mode (v4) and upload the data to your server. 使用在提升模式(v4)上运行的Silverlight客户端应用程序,并将数据上传到您的服务器。
  • refer your clients to download application (the C# application you wrote about) and run it - this application will upload the data to your server. 请您的客户下载应用程序(您编写的C#应用​​程序)并运行它-该应用程序会将数据上传到您的服务器。

hope this helps. 希望这可以帮助。

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

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