Gate adds OWIN support for the new ASP.NET Web API beta
Gate, internet, opensource, OWIN, programming, web, webapi February 20th, 2012Hello again, everyone! As I’m sure you already know, ASP.NET MVC 4 beta is available and it has some fantastic stuff in it! One of the interesting bits is the latest ASP.NET Web API.
Looking at that, I’m absolutely certain you’re thinking the same thing Glenn Block was saying on Twitter:
@gblock: hmm I really wish there was an Owin adapter for #aspnetwebapi! /cc:@loudej
Wish no longer! Gate has a new drop available, version 0.3.4, and it contains a Get.Adapters.AspNetWebApi package which does exactly that – enabling you to mix the Web API into your OWIN based web applications.
Let’s take a look at how that feels. That should be even easier than before because of a few more things that are new in Gate – a handful of Quickstart nuget packages, and a Ghost “generic host” process which lets you use any of the available OWIN http servers interchangeably. Neat, right? Let’s jump right into that!
First – start with a new “ASP.NET Empty Web Application”
Then – to make it “really empty” – let’s remove a bunch of references. This step is optional, but should be very satisfying if you want to see some minimalism in action. Quickest way is to select the last assembly reference and lean on the “delete” key.
Finally let’s add the meta-package Gate.Quickstart.AspNetWebApi from Nuget.org.
PM> Install-Package Gate.Quickstart.AspNetWebApi Attempting to resolve dependency 'Gate.Quickstart.Core (≥ 0.3.4)'. Attempting to resolve dependency 'Gate.Hosts.AspNet (≥ 0.3.4)'. Attempting to resolve dependency 'Gate.Builder (≥ 0.3.4)'. Attempting to resolve dependency 'Owin (≥ 0.7.0)'. Attempting to resolve dependency 'Microsoft.Web.Infrastructure (≥ 1.0.0.0)'. Attempting to resolve dependency 'Gate.Middleware (≥ 0.3.4)'. Attempting to resolve dependency 'Gate (≥ 0.3.4)'. Attempting to resolve dependency 'Gate.Adapters.AspNetWebApi (≥ 0.3.4)'. Attempting to resolve dependency 'AspNetWebApi.Core (≥ 4.0.20126.16343)'. Attempting to resolve dependency 'System.Net.Http.Formatting (≥ 4.0.20126.16343)'. Attempting to resolve dependency 'System.Net.Http (≥ 2.0.20126.16343)'. Attempting to resolve dependency 'System.Web.Http.Common (≥ 4.0.20126.16343)'. Attempting to resolve dependency 'System.Json (≥ 4.0.20126.16343)'.
You can now press F5 and see this run. The quickstart adds an example Startup class -which is using a partial class trick because I wanted you to be able to add more then one demo to the same project. But that’s not really necessary – in your own projects a simpler Startup class like this would work exactly the same.
using System.Net;
using System.Net.Http;
using System.Web.Http;
using Gate.Adapters.AspNetWebApi;
using Owin;
namespace HelloEverything
{
public class Startup
{
public void Configuration(IAppBuilder builder)
{
var config = new HttpConfiguration(new HttpRouteCollection("/"));
config.Routes.MapHttpRoute(
"Default",
"{controller}",
new {controller = "Main"});
builder
.RunHttpServer(config);
}
public void Debug(IAppBuilder builder)
{
builder.UseShowExceptions();
Configuration(builder);
}
}
public class MainController : ApiController
{
public HttpResponseMessage Get()
{
return new HttpResponseMessage(HttpStatusCode.OK)
{
Content = new StringContent("Hello, AspNetWebApi!")
};
}
}
}
Next you should try adding the meta-meta-package Gate.Quickstart.All. Then you’ll be able to press F5 to see a demo of everything and the kitchen sink: Web API, Nancy, SignalR, Gate “test page”, and Direct output from code (res.Write style).
Direct output is kind of interesting, looks like this:
public class Startup
{
public void Configuration(IAppBuilder builder)
{
builder.RunDirect((req,res) =>
{
res.ContentType = "text/plain";
res.Write("Hello, ").Write(req.PathBase).Write(req.Path).Write("!");
res.End();
});
}
}
Well – that’s probably long enough for this post. Next topic – hopefully soon – will be about using the Ghost.exe “generic host” to run this web application on HttpListener, Kayak, or Firefly.


February 20th, 2012 at 1:57 pm
[...] This is using the OWIN web app we made in the last post. [...]
February 21st, 2012 at 8:38 am
[...] Gate adds OWIN support for the new ASP.NET Web API beta and Ghost.exe – a generic host for OWIN applications (Louis DeJardin) [...]
March 5th, 2012 at 6:53 am
[...] DeJardin created a host on top of [...]
August 22nd, 2012 at 9:44 pm
I simply could not leave your web site before suggesting that I extremely enjoyed the standard info a person provide to your visitors? Is gonna be again steadily to inspect new posts
September 4th, 2012 at 3:32 am
Good day! Just recently found a site on the Internet kamkam.rf . This is a site for singles, where video chat. Sort of liked the site : the design of a simple , not annoying. Even a pleasant one: check-in took only a few minutes. On this site is a sufficient number of registered – about one million . A video chat option is convenient – Roulette.That is, you come into the chat and your registered users are offered absolutely right.
But , to be honest , once I ‘m afraid to make friends while on this site. Maybe there are not real people .
People , share, maybe someone has already registered on this site? Maybe tell me what and how? Share experiences so to speak . Thank you all in advance for the information , I would appreciate any information – positive or not.
December 15th, 2012 at 5:39 am
People , share, maybe someone has already registered on this site? Maybe tell me what and how? Share experiences so to speak . Thank you all in advance for the information , I would appreciate any information – positive or not – ???
???
Now khow
January 27th, 2013 at 7:43 am
Is it possible to write a simple custom Console Application that includes a owin library that can host a Asp.Net Web Application directly (without katana.exe, like CassiniDev’s library)?
Is it possible to let an Asp.Net Web Application including MVC 4, Web API, SignalR features hosted across IIS and owin, without / rarely changing code?