新建Web API工程

ASP.NET Web API Demo OwinSelfHost 自宿主 Swagger Swashbuckle 在线文档

 

ASP.NET Web API Demo OwinSelfHost 自宿主 Swagger Swashbuckle 在线文档

选Empty,勾选Web API,不要选择Web API,那样会把MVC勾上,这里不需要MVC

Web API工程属性

ASP.NET Web API Demo OwinSelfHost 自宿主 Swagger Swashbuckle 在线文档

 XML文件用于生成在线文档

  新建Windows服务作为Web API的宿主

 ASP.NET Web API Demo OwinSelfHost 自宿主 Swagger Swashbuckle 在线文档

WebApiHost工程属性

ASP.NET Web API Demo OwinSelfHost 自宿主 Swagger Swashbuckle 在线文档

 控制台应用程序方便调试

 Windows服务安装Microsoft.AspNet.WebApi.OwinSelfHost

 ASP.NET Web API Demo OwinSelfHost 自宿主 Swagger Swashbuckle 在线文档

工程WebApiDemo需要引用Microsoft.Owin.dll

 WebApiDemo安装Swashbuckle

ASP.NET Web API Demo OwinSelfHost 自宿主 Swagger Swashbuckle 在线文档

 应用程序入口

using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.ServiceProcess;
using System.Text;
using System.Threading.Tasks;

namespace WebApiHost
{
    static class Program
    {
        /// <summary>
        /// 应用程序的主入口点。
        /// </summary>
        static void Main(string[] args)
        {
            RunDebug();
            StartService();
        }

        private static void StartService()
        {
            ServiceBase[] ServicesToRun;
            ServicesToRun = new ServiceBase[]
            {
                new WebApiHostService()
            };
            ServiceBase.Run(ServicesToRun);
        }

        [Conditional("DEBUG")]
        private static void RunDebug()
        {
            new WebApiHostService().Start();
            Console.WriteLine("启动成功");
            Console.ReadLine();
        }
    }
}
View Code

相关文章:

  • 2021-07-04
  • 2021-08-21
  • 2021-11-30
  • 2021-06-22
  • 2022-12-23
  • 2021-08-17
猜你喜欢
  • 2021-05-24
  • 2021-05-24
  • 2022-12-23
  • 2021-08-14
相关资源
相似解决方案