2012-11-08 16 views
6

Sto cercando l'equivalente Jetty nel codice gestito da Net Framework. Esiste? Vorrei usare la libreria da un'applicazione F #/C#/VB.net. "Non distribuire l'applicazione in Jetty, distribuire Jetty nella propria applicazione."Jetty for NET world

+1

Una domanda simile è stata posta una volta: http://stackoverflow.com/questions/4268814/embedded-c-sharp-web-server – Jensen

+0

grazie mille! Mi aiuta. – dag

+2

Potresti essere interessato anche a [ServiceStack] (http://servicestack.net/). Inoltre ci sono diversi framework qui elencati che sono compatibili con [OWIN] (http://owin.org/). –

risposta

5

Quanto sofisticate API stai cercando? Per compiti semplici, penso che puoi ottenere abbastanza lontano semplicemente utilizzando il tipo standard HttpListener. Esiste un esempio MSDN che lo incapsula con un agente F # (part 3) e quindi lo utilizza per creare un semplice server di chat (part 4).

La parte centrale del server di chat sembra abbastanza semplice:

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 } 

Una biblioteca più avanzata disponibile per F # potrebbe essere Frack (Un'implementazione del Open Web Interface for .NET (OWIN), un .NET Interfaccia Web Server Gateway, scritta in F #). Anche questo sembra molto facile da usare.

4

ServiceStack viene eseguito anche all'interno di un'applicazione HttpListener ospitata in Win/.NET o Mono/Linux (oltre a un host ASP.NET).

Vedere lo self-hosted wiki page per semplici esempi di ServiceStack in esecuzione in app di console C# o F #.