Wrap WebAPI RESTful service with Self Host in C#

selfhost
1. Create “Console Application”.
2. Change “.Net Framework Client Profile” to “.Net Framework”!
3. Open “Package Manager Console” and run:

Install-Package Microsoft.AspNet.WebApi.SelfHost -Version 4.0.30506

Version can be removed if you’re using .Net >= 5
4. Add your Models and Controllers to the project.
5. Add code to Main method:

class Program {
  public static void Main(string[] args) {
    var config = new HttpSelfHostConfiguration("http://localhost:8080");

    config.Routes.MapHttpRoute(
        "API Default", "api/{controller}/{id}", 
        new { id = RouteParameter.Optional });

    using (var server = new HttpSelfHostServer(config))
    {
        server.OpenAsync().Wait();
        Console.WriteLine("Press  to quit.");
        Console.ReadLine();
    }
  }
}

6. Run application!

More info,
http://www.asp.net/web-api/overview/hosting-aspnet-web-api/self-host-a-web-api,
http://pfelix.wordpress.com/2012/03/08/asp-net-web-api-self-hosting/