如何从网络控制 C# 程序?也许使用 AJAX?
谁能解释如何将变量从网络(PHP、Javascript 等)发送到 C# 程序?我想让网络告诉程序该做什么。也许我可以使用 AJAX 将数据发送到自动更新页面,然后 C# 程序可以读取该页面?这还允许用户登录该页面,因此可以将不同的数据发送给每个用户。有人可以解释一下这是如何做到的吗?
Can anyone explain how to send variables from the web (PHP, Javascript, etc.) to a C# program? I want to allow the web to tell the program what to do. Maybe I could use AJAX to send data to an auto-updating page, which the C# program can then read? That would also allow users to be logged-in to the page and therefore different data could be sent to each user. Could someone explain how this could be done?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
您可以在 .NET 中构建 Web 服务。最好的方法是使用 Windows Communication Foundation (WCF) 。
然后,您可以在 javascript 中编写 代码 来调用网络服务。
You could build a webservice in .NET. The best way to do so is with Windows Communication Foundation (WCF).
Then you could write code in your javascript to make calls to the webservice.
为什么不让它监听套接字上的命令呢?
http://msdn.microsoft.com/ en-us/library/system.net.sockets.socket.listen.aspx
Why not just have it listen for commands on a socket?
http://msdn.microsoft.com/en-us/library/system.net.sockets.socket.listen.aspx
由于对 C# 程序的调用存在并发性,这可能会很棘手。
您可以创建一个 Web 服务,该服务以变量作为参数来启动 C# 程序。
或者,您可以将变量写入表中,并让 C# 程序轮询该表中的新条目。这将克服并发问题。与将变量写入表的 WebService 相结合 - 该解决方案工作得很好。
Well this might be tricky because of the concurrency on the calls to the C# programm.
You could create a Webservice that is starting the C# program with the variables as arguments.
Or you might write the variables into a table and have the C# program poll for new entries to that table. This would overcome the concurrency issue. Combined with a WebService that writes the variables into the a table - this solution is working just fine.
这里有两个解决方案:
You have two solutions here :