Created
June 15, 2016 14:28
-
-
Save irokhes/2f01df2210b22d257e7e3afea4cb9845 to your computer and use it in GitHub Desktop.
Web api service self hosted using OWIN
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using Microsoft.Owin.Hosting; | |
using System; | |
using System.Net.Http; | |
//Install-Package Microsoft.AspNet.WebApi.OwinSelfHost | |
namespace WebApi.SelfHosting.POC | |
{ | |
static class Program | |
{ | |
static void Main() | |
{ | |
string baseAddress = "http://localhost:8888/"; | |
// Start OWIN host | |
using (WebApp.Start<Startup>(baseAddress)) | |
{ | |
Console.WriteLine("Press Enter to quit."); | |
Console.ReadKey(); | |
} | |
Console.ReadLine(); | |
} | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using Owin; | |
using System.Web.Http; | |
//Install-Package Microsoft.AspNet.WebApi.OwinSelfHost | |
namespace WebApi.SelfHosting.POC | |
{ | |
public class Startup | |
{ | |
// This code configures Web API. The Startup class is specified as a type | |
// parameter in the WebApp.Start method. | |
public void Configuration(IAppBuilder appBuilder) | |
{ | |
// Configure Web API for self-host. | |
HttpConfiguration config = new HttpConfiguration(); | |
config.Routes.MapHttpRoute("DefaultApi", "{controller}/{id}", new{ id = RouteParameter.Optional }); | |
appBuilder.UseWebApi(config); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment