33

In Java I've been able to embed* the jetty server in my apps, but is there an equivalent embedded* server technology for .Net?

Open source (FLOSS) would be preferred if possible.

*by embedded I mean a lightweight web server app that could be packaged with my application and run on a user's local desktop machine to provide a web service locally.

Iain Sproat
  • 5,210
  • 11
  • 48
  • 68
  • 2
    Cassini is tiny, and good enough for many purposes. There are also many cassini derivatives better than the original: http://www.codeplex.com/site/search?query=cassini&ac=8 – MatthewMartin Nov 24 '10 at 16:07
  • Any preference between CassiniDev, Cassini++ or Cassini 3.5? – Iain Sproat Nov 24 '10 at 18:50

5 Answers5

25

The closest equivalent to Jetty I've found so far is Nancy, described as:

a lightweight, low-ceremony, framework for building HTTP based services on .Net and Mono.

Nancy is designed to handle DELETE, GET, HEAD, OPTIONS, POST, PUT and PATCH requests

Nancy was designed to not have any dependencies on existing frameworks. Built with the .NET framework client profile, Nancy can be used pretty much wherever you want to, since it’s completely self contained with it’s own request and response objects.

One of the core concepts in Nancy is hosts. A host acts as an adaptor for a hosting environment and Nancy, thus enabling Nancy to run on existing technologies such as ASP.NET, WCF and OWIN, or integrated in any given application.

An even more lightweight option is Kayak (Update: project looks dead as of 2014-01-18), which its documentation describes as:

a simple web server. It listens for connections, creates an in-memory representation of requests, and allows you to easily generate responses. It can be used in any C# program. Your code loads Kayak into its process space—not the other way around!

and both Nancy and Kayak are MIT licensed.

Community
  • 1
  • 1
Iain Sproat
  • 5,210
  • 11
  • 48
  • 68
  • Does Kayak only serve static html or can an ASP.Net application be hosted with it? – Jeff LaFay Jan 03 '11 at 23:13
  • 6
    Nancy is NOT a webserver. It is middleware. You need to run Nancy on a webserver (and in fact Nancy will run on Kayak AFAIK (when Kayak is configured for OWin)). In fact I would suggest that the Nancy/Kayak stack is what you are looking for. – Aron Mar 18 '14 at 04:30
  • 2
    True, the core part of Nancy is not a web server in itself. However, I believe the Nancy.SelfHosting library is. – Iain Sproat Mar 28 '14 at 16:31
  • 1
    @sprocketonline Nancy.SelfHosting uses `HttpListener` which hooks into IIS via WAS. – Aron Jun 06 '16 at 06:46
15

Here's another alternative I wrote last year and and has served me well.

EmbedIO: https://github.com/unosquare/embedio

I use it mostly to create RESTful services on the Raspberry Pi (soft-float).

Edit: Updated code for Mono 3.10, support for WebSockets, and Asynchronous handling of requests.

Mario
  • 659
  • 7
  • 12
  • doesn't support .net 4, :( – Benny May 27 '15 at 03:46
  • With less than 10 lines of code, I have a web server serving static files. I wish it provides a way to print url after it is completely served. Otherwise it is small and reliable. – videoguy Feb 18 '16 at 23:23
  • @videoguy That's a very simple thing to do. You can simply create a module that extends WwebModuleBase and have the handler return false after printing the Url. See an example here: https://github.com/unosquare/embedio/blob/master/Unosquare.Labs.EmbedIO/Modules/StaticFilesModule.cs#L147 – Mario May 09 '16 at 14:42
  • I followed your suggestion and I am able to log each web request to UI log panel. @Mario Does this lib support listening on https:// ports? – videoguy Apr 07 '17 at 13:18
8

Update for 2016:

The new kid on the block is Kestrel.

Kestrel is an open source web server that is a part of the ASP NET Core initiative by Microsoft. It is an event based webserver built upon libuv (it basically node.js - js + .net). This means that it should be easily portable between different operating system. Unfortunately, it does mean it requires an external native dependency. *

https://github.com/aspnet/KestrelHttpServer

An older project that does this is Nowin

https://github.com/Bobris/Nowin/tree/master/Nowin

This is an implementation of Owin built entirely within .net. Unfortunately, it has been deprecated in favor for Kestrel.

Edit: * The newest version of Kestrel has dropped libuv for a managed dotnet socket approach. This of course means Kestrel no longer has a native dependency.

Aron
  • 15,464
  • 3
  • 31
  • 64
3

The one that is used with Visual Studio is called cassini. There is a good derivative called UltiCassini.

Buddy Lindsey
  • 3,560
  • 6
  • 30
  • 42
1

The solution from Microsoft itself is called Katana,

https://katanaproject.codeplex.com/

Note that it is fully open sourced, under Apache license.

Lex Li
  • 60,503
  • 9
  • 116
  • 147