????????????ASP.NET Web API???д???????????????????????????????????????????
??????Web API??????????????????μ??????
????????????
????1????IIS?д????????????Web API???
????2????hosts?????????IP???????
????????????????
????3???????????F6????
????4????TestDriven.Net???е??????
????????????????????????????????????????????????????κγ???????????????????譴F6??????????е??????????????????
??????????????????????????????????????????£????????????????????????Owin Host???????????????????????
??????Owin Host?????·???????????????????Owin Host????ASP.NET Web API????????????????????????Owin Host?????в????
?????????Web API????????ASP.NET 4.5 + ASP.NET Web API 5.2.3??????????OWIN????????????????Web API?????????Щ???? ??????Owin Host??????????
????????nuget???Owin??????IAppBuilder?????У???
????PM> Install-Package Owin
??????????Startup.cs??
????public class Startup
????{
????public void Configuartion(IAppBuilder app)
????{
????}
????}
????????nuget???Microsoft.AspNet.WebApi.Owin??????app.UseWebApi????????????У?
????PM> Install-Package Microsoft.AspNet.WebApi.Owin
??????Startup.Configuratrion????????????????WebApiConfig.Register?????????????????????·???????????У?????HttpConfiguration?????????OWIN??????С?
????public class Startup
????{
????public void Configuration(IAppBuilder app)
????{
????var configuraton = new HttpConfiguration();
????WebApiConfig.Register(configuraton);
????app.UseWebApi(configuraton);
????}
????}
????Web API??????????????????£????????Owin Host?????κθ?????????????IIS???????
??????????????????????????????????????Microsoft.Owin.Hosting?е?WebApp.Start()????????Web API???
????????nuget???Owin Host???????
????PM> Install-Package Microsoft.Owin.Hosting
????PM> Install-Package Microsoft.Owin.Host.HttpListener
???????????????????????????WebApp.Start()???Web API???
????public class CommentsWebApiTest : IDisposable
????{
????private const string HOST_ADDRESS = "http://localhost:8001";
????private IDisposable _webApp;
????public CommentsWebApiTest()
????{
????_webApp = WebApp.Start<Startup>(HOST_ADDRESS);
????Console.WriteLine("Web API started!");
????}
????public void Dispose()
????{
????_webApp.Dispose();
????}
????}
??????????????IIS???????????Web API???????????
???????????????????£?
????1????Web API???????????ApiController
????public class CommentsController : ApiController
????{
????[Route("blogposts/{postId}/comments")]
????public async Task<IHttpActionResult> Get(int postId)
????{
????var comments = new Comment[] { new Comment {
????PostId = postId??
????Body = "Coding changes the world1" } };
????return Ok<Comment[]>(comments);
????}
????}