Skip to content

Instantly share code, notes, and snippets.

@irokhes
Created June 15, 2016 14:28
Show Gist options
  • Save irokhes/2f01df2210b22d257e7e3afea4cb9845 to your computer and use it in GitHub Desktop.
Save irokhes/2f01df2210b22d257e7e3afea4cb9845 to your computer and use it in GitHub Desktop.
Web api service self hosted using OWIN
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();
}
}
}
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