douliao7930 2011-09-07 13:51
浏览 56
已采纳

在当前正在运行的控制台应用程序中调用方法。

I have a console application I wrote in C# that polls multiple devices, collects some data, and stores the information on a database. The application runs on our web server, and I was wondering how to invoke a method call from the command console (so I can exec a command from php that will be read by the console application, a shell command would work as well).

Anyone got any ideas? I've been floating around 'the google' and have found nothing that will supply my current needs.

Also, i'm not adverse to making changes to the console application if an overhaul is needed there. Please, if your answer is COM Interop, provide a GOOD example of how I would build and call this from PHP / Apache2.

  • 写回答

3条回答 默认 最新

  • dounie5475 2011-09-07 14:13
    关注

    You could create a Service like this:

    [ServiceContract]
    public interface IService
    {
        [OperationContract]
        [WebInvoke(
          Method = "GET",
          UriTemplate = "/magic")]
        void MagicMethod();
    
    }
    

    And a service implementation like this:

    public class Service : IService
    {
        public void MagicMethod()
        {
            //magic here
        }
    }
    

    to start a HTTP Service it should look like this:

    WebServiceHost host = new WebServiceHost(typeof(Service), new Uri("http://127.0.0.1:8080"))
    ServiceEndpoint ep = host.AddServiceEndpoint(typeof(IService), new WebHttpBinding(), "");
    ServiceDebugBehavior stp = host.Description.Behaviors.Find<ServiceDebugBehavior>();
    
    stp.HttpHelpPageEnabled = false;
    host.Open();  
    

    This will start a HTTP server on port 8080. Then you can make a HTTP Get request to 'http://localhost:8080/magic' to invoke the method call.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥50 导入文件到网吧的电脑并且在重启之后不会被恢复
  • ¥15 (希望可以解决问题)ma和mb文件无法正常打开,打开后是空白,但是有正常内存占用,但可以在打开Maya应用程序后打开场景ma和mb格式。
  • ¥20 ML307A在使用AT命令连接EMQX平台的MQTT时被拒绝
  • ¥20 腾讯企业邮箱邮件可以恢复么
  • ¥15 有人知道怎么将自己的迁移策略布到edgecloudsim上使用吗?
  • ¥15 错误 LNK2001 无法解析的外部符号
  • ¥50 安装pyaudiokits失败
  • ¥15 计组这些题应该咋做呀
  • ¥60 更换迈创SOL6M4AE卡的时候,驱动要重新装才能使用,怎么解决?
  • ¥15 让node服务器有自动加载文件的功能