Skip to content

Instantly share code, notes, and snippets.

@mythz
Created September 28, 2011 06:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save mythz/1247149 to your computer and use it in GitHub Desktop.
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
(* 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