创建像 windows 服务和 restful 服务器一样的 wcf 自宿主应用程序?

Create wcf self host application that will act like windows service and also as restful server?

是否可以创建将公开 restful Web 服务并像 windows 服务一样运行(将在机器启动时启动)的自托管 wcf 应用程序?

如果您想在 Windows 服务中使用 RESTful 服务,您是否考虑过使用 TopShelf self-hosting ASP.NET Web API?

http://codeopinion.com/self-host-asp-net-web-api-as-a-windows-service/

您可以使用 windows 服务托管 WCF 服务,然后可以通过 HTTP 请求访问它(只要端口打开等)

只需创建您的 WCF 库和一个 windows 解决方案服务项目。

然后编辑静态class程序通常在program.cs 托管服务。

static class Program 
    {
        /// <summary>
        /// The main entry point for the application.
       /// </summary>
        static void Main()
        {
            ServiceBase[] ServicesToRun = new ServiceBase[] 
            { 
                new WCFService() 
            };
            ServiceBase.Run(ServicesToRun);
        }
    }