Damian Hickey

Mostly software and .NET related. Mostly.

ServiceStack OWIN support sneak peek

Something I am currently kicking the tyres of, and am sucessfully using in a limited fashion thus far, is using ServiceStack on OWIN. The code currently resides on a branch in my fork and I'm going to bake it a bit more before sending a pull request. 

So what will it look like?

Using ServiceStack's HelloWorld as an example, we create the OWIN Host:

public class HelloOwinHost : OwinHostBase
	public HelloOwinHost() : base("Hello Web Services", typeof(HelloService).Assembly) { }

	public override void Configure(Container container)

Only difference between this and the original example is that we're inheriting from OwinHostBase instead of AppHostBase.

Here is how you host this on Microsoft.HttpListener.Owin - a server based on .net http listener from the KatanaProject - and using some helper nuget packages (Owin.Startup and Owin.Builder):

//Initialize the Owin host
var helloOwinHost = new HelloOwinHost();

// Use Owin.Startup.AppBuilder to help configure the server
var app = new AppBuilder();

//We tell the server where to listen and where to delegate requests to
app.SetHostAddress("http", "+", 8080)
	.Run(new Func<IDictionary<string, object>, Task>(helloOwinHost.ProcessRequest));

//Create the server and test with a client
using (ServerFactory.Create(app.Build(), app.Properties))
using(var client = new XmlServiceClient("http://localhost:8080"))
	var response = client.Send<HelloResponse>(new Hello {Name = "Damian"});
	Assert.AreEqual("Hello, Damian", response.Result);

Overall, pretty standard OWIN stuff. Full source of this example is on github if you want to clone and run it.

The interesting things start to happen when you combine multiple OWIN supporting frameworks (Nancy, Signalr, ServiceStack) behind a single server in your own process... more on that later :)

Upcoming improvements in RavenDB's packages

As of the current release, 1.0.960, when installing RavenDB.Embedded your project's references would look something like this, not including your own references:

For 1.2.x, it looks like this:

This pleases me.

The main changes include:

  1. Raven now uses a dynamic logging abstraction. The RavenDB.Client and .Database projects no longer directly depend on NLog, but actually support NLog and Log4Net dynamically. All you have to do is reference either library and RavenDB will use it. The logging http endpoint is now per database.
  2. Newtonsoft.Json, a source of much grief amonst the current 1.0.x users, has been imported and internalized. 
  3. Raven.Munin, Raven.Storage.Esent and Raven.Storage.Managed have been merged into Raven.Database.
  4. Raven.Backup and Raven.Smuggler... well they shouldn't have been there in the first place.
  5. The packages use the <references> element to explicitly define what should be referenced, so BouncyCastle.Crypto, Lucene.* etc will no longer be exposed to you.
  6. Raven.Studio.xap is embedded into Raven.Database, so it will no longer be added to your project. You can still deploy an updated xap which will override the embedded one, if you so wish.
  7. Raven.Client.Debug has been discontinued.

You can try these out in the next day or so by installing the unstable packages from nuget ( install-package RavenDB.Embedded -pre). Any feedback, please post to the google group.