dongshijiao2363
dongshijiao2363
2010-08-06 13:40

如何从网上控制C#程序? 使用AJAX可能吗?

已采纳

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?

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享
  • 邀请回答

4条回答

  • dongzhang6677 dongzhang6677 11年前

    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.

    点赞 评论 复制链接分享
  • duanpi2033 duanpi2033 11年前

    You have two solutions here :

    • Build a WCF service that you'll then use by doing SOAP calls
    • Use a Socket to communicate
    点赞 评论 复制链接分享
  • douchengchen7959 douchengchen7959 11年前

    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.

    点赞 评论 复制链接分享
  • doujiaochan7317 doujiaochan7317 11年前

    Why not just have it listen for commands on a socket?

    http://msdn.microsoft.com/en-us/library/system.net.sockets.socket.listen.aspx

    点赞 评论 复制链接分享