In this short tutorial, I will tell you how to self-host the Web API, using OWIN custom host. First step that you must do is Add a new Console application as you can see on the below picture.

Next, in order to make a web API and use OWIN custom host, we tend to add references to Microsoft.AspNet.WebApi.OwinSelfHost, using the Nuget Package Manager. this may not only add the references for the web API however also the OWIN components, along with the opposite needed dependencies.

Add a replacement web API controller class. we tend to take away all the methods and add an easy GET method to get the sum of two random numbers.

Add a new class named Startup.cs. this can be as per the OWIN specifications. Use the HttpConfiguration class to make the web API routing template and add it to the request pipeline using the appBuilder.UseWebApi method, where appBuilder is of type IAppBuilder.

Open the Program.cs file and begin the server using the WebApp.Start method, specifying the StartUp class because the entry point for the settings needed. this is the OWIN specification of starting the server within the custom host.

Now simply run the application and the server is started.

To test the Web API, we’ll use the Chrome browser Postman extension. So type the URL of the Web API that we specified in the Program.cs and Send the request. See the results received as you can see on the following picture:

Free ASP.NET Hosting with OWIN Support

Try our Free ASP.NET Hosting with OWIN Support today and your account will be setup soon! You can also take advantage of our Windows & ASP.NET Hosting support with Unlimited Domain, Unlimited Bandwidth, Unlimited Disk Space, etc. You will not be charged a cent for trying our service for the next 3 days. Once your trial period is complete, you decide whether you'd like to continue.