控制台托管Webapi

using System.Web.Http;

using System.Web.Http.SelfHost;



Console.WriteLine("输入1 启动服务,其他值查看http://localhost:8080/api/Products返回结果");

            if (Console.ReadLine() == "1")
            {
                var config = new HttpSelfHostConfiguration("http://localhost:8080");


                config.Routes.MapHttpRoute(
                    "API Default", "api/{controller}/{id}",
                    new { id = RouteParameter.Optional });


                using (HttpSelfHostServer server = new HttpSelfHostServer(config))
                {
                    server.OpenAsync().Wait();
                }
            }
            else
            {
                string re = WebApiServer.HttpGet("http://localhost:8080/api/Products");
                Console.WriteLine(re);


            }
            Console.WriteLine("Press Enter to quit.");
            Console.ReadLine();

猜你喜欢

转载自blog.csdn.net/qqqgg/article/details/79860897