6

I am looking for the Jetty equivalent in the Net Framework world - managed code. Does it exist? I would like to use the library from an F#/C#/VB.net application. "Don't deploy your application in Jetty, deploy Jetty in your application."

mmmmmm
  • 32,227
  • 27
  • 88
  • 117
dag
  • 288
  • 2
  • 10
  • 1
    A similar question was once asked: http://stackoverflow.com/questions/4268814/embedded-c-sharp-web-server – Jensen Nov 08 '12 at 15:07
  • 2
    You might also be interested in [ServiceStack](http://servicestack.net/). Also there are several frameworks listed here that are compatible with [OWIN](http://owin.org/). – Joel Mueller Nov 08 '12 at 15:52

2 Answers2

5

How sophisticated API are you looking for? For simple tasks, I think you can get fairly far just by using the standard HttpListener type. There is an MSDN sample that encapsulates it with an F# agent (part 3) and then uses it to create a simple chat server (part 4).

The core part of the chat server looks fairly straightforward:

let handleRequest (context:HttpListenerContext) = async { 
    match context.Request.Url.LocalPath with 
    | "/post" -> 
        // Send message to the chat room
        room.SendMessage(context.Request.InputString)
    | "/chat" -> 
        // Get messages from the chat room (asynchronously!)
        let! text = room.AsyncGetContent()
        context.Response.Reply(text)
    | s ->
        // Omitted: handle file request }

A more advanced library available for F# might be Frack (An implementation of the Open Web Interface for .NET (OWIN), a .NET Web Server Gateway Interface, written in F#.) This also looks very easy to use.

ildjarn
  • 62,044
  • 9
  • 127
  • 211
Tomas Petricek
  • 240,744
  • 19
  • 378
  • 553
4

ServiceStack also runs inside a self-hosted HttpListener application in Win/.NET or Mono/Linux (in addition to an ASP.NET host).

See the self-hosted wiki page for simple examples of running ServiceStack in a C# or F# Console apps.

mythz
  • 141,670
  • 29
  • 246
  • 390