如何在WCF服务运行之前运行IIS?

时间:2014-07-30 21:11:19

标签: wcf iis

如何在 WCF服务运行之前从web.config 运行IIS

1 个答案:

答案 0 :(得分:0)

我在程序开头找到了运行IIS服务的解决方案,如下所示:

    [STAThread]
    static void Main()
    {
        StartIISService();
        Application.Run(new MainForm());
    }

    private static void StartIISService()
    {
        ServiceController controller = new ServiceController();
        controller.ServiceName = "W3SVC";
        controller.MachineName = SystemInformation.ComputerName;
        if (controller.Status != ServiceControllerStatus.Running)
            controller.Start();
        controller.Dispose();
    }