Created
September 28, 2011 06:36
-
-
Save mythz/1247149 to your computer and use it in GitHub Desktop.
Stand-alone Hello World ServiceStack Web Service with F# on Mono/OSX hosted by HttpListener
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(* Stand-alone Hello World ServiceStack Web Service with F# on Mono/OSX hosted by HttpListener | |
Instructions: | |
1) download https://github.com/ServiceStack/ServiceStack/downloads | |
2) fsharpc -r:ServiceStack.Common.dll -r:ServiceStack.Interfaces.dll -r:ServiceStack.Text.dll -r:ServiceStack.dll Hello.fs | |
3) sudo mono Hello.exe | |
Read More: For the benefits of a ServiceStack Hello World Service see: http://www.servicestack.net/ServiceStack.Hello/ | |
*) | |
open System | |
open ServiceStack.ServiceHost | |
open ServiceStack.WebHost.Endpoints | |
type Hello = { mutable Name: string; } | |
type HelloResponse = { mutable Result: string; } | |
type HelloService() = | |
interface IService<Hello> with | |
member this.Execute (req:Hello) = { Result = "Hello, " + req.Name } :> Object | |
//Define the Web Services AppHost | |
type AppHost = | |
inherit AppHostHttpListenerBase | |
new() = { inherit AppHostHttpListenerBase("Hello F# Services", typeof<HelloService>.Assembly) } | |
override this.Configure container = | |
base.Routes | |
.Add<Hello>("/hello") | |
.Add<Hello>("/hello/{Name}") |> ignore | |
[<EntryPoint>] | |
let main args = | |
let host = if args.Length = 0 then "http://*:8080/" else args.[0] | |
printfn "listening on %s ..." host | |
let appHost = new AppHost() | |
appHost.Init() | |
appHost.Start host | |
Console.ReadLine() |> ignore | |
0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment