码迷,mamicode.com
首页 > Windows程序 > 详细

owin建控制台应用程序步骤

时间:2016-11-17 07:50:10      阅读:236      评论:0      收藏:0      [点我收藏+]

标签:建立   配置   ogr   route   web   map   str   read   string   

1.  Install-Package Microsoft.AspNet.WebApi.OwinSelfHost

2.  建立OWIN Startup类

public void Configuration(IAppBuilder app)
{

HttpConfiguration config = new HttpConfiguration();

config.Routes.MapHttpRoute(
name: "DefaultApi",
routeTemplate: "api/{controller}/{id}",
defaults: new { id = RouteParameter.Optional }
);
//将默认xml返回数据格式改为json
config.Formatters.XmlFormatter.SupportedMediaTypes.Clear();
config.Formatters.JsonFormatter.MediaTypeMappings.Add(new QueryStringMapping("datatype", "json", "application/json"));

app.UseWebApi(config);
// 有关如何配置应用程序的详细信息,请访问 http://go.microsoft.com/fwlink/?LinkID=316888

}

 

3. Program中启动

static void Main(string[] args)
{
string baseAddress = "http://localhost:9000/";
Microsoft.Owin.Hosting.WebApp.Start<Startup>(url: baseAddress);
Console.WriteLine("程序已启动,按任意键退出");
Console.ReadLine();
}

 

4. 建立controller:ApiController

5. 配置外网访问地址

 

owin建控制台应用程序步骤

标签:建立   配置   ogr   route   web   map   str   read   string   

原文地址:http://www.cnblogs.com/yyyymmmmdddd/p/6072202.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!