Skip to content

Instantly share code, notes, and snippets.

@kflu
Created February 15, 2017 01:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kflu/32e0ec23eb8a57294fa2ab1e5bd33869 to your computer and use it in GitHub Desktop.
Save kflu/32e0ec23eb8a57294fa2ab1e5bd33869 to your computer and use it in GitHub Desktop.
Vanilla self host ASP.NET web API application
namespace Foo
{
using System;
using System.Net;
using System.Threading;
using System.Linq;
using System.Collections.Generic;
using System.Text;
using Newtonsoft.Json;
using System.Web.Http;
using System.Web.Http.SelfHost;
/// <summary>
/// Main class
/// </summary>
public static class MainClass
{
static void Main(string[] args)
{
var addr = new Uri("http://localhost:8001");
using (var config = new HttpSelfHostConfiguration(addr))
{
config.Routes.MapHttpRoute("default", "api/{controller}");
using (var srv = new HttpSelfHostServer(config))
{
srv.OpenAsync().Wait();
Console.WriteLine("Server started");
Console.ReadLine();
Console.WriteLine("done");
}
}
}
}
public class ProductController : ApiController
{
public class Result
{
public int Code;
public object Metadata;
}
[HttpPost]
public Result Post([FromBody]int[] data)
{
return new Result
{
Code = 1,
Metadata = data,
};
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment