Skip to content

Instantly share code, notes, and snippets.

@mythz
Created September 28, 2011 10:14
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mythz/1247567 to your computer and use it in GitHub Desktop.
Save mythz/1247567 to your computer and use it in GitHub Desktop.
Hello World ServiceStack ASP.NET Web Service in F#
<%@ Application Inherits="HelloFSharp.Global" %>
(* Hello World ServiceStack ASP.NET Web Service in F#
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 --target:library HelloAsp.fs
3) mkdir bin && cp *.dll bin
4) echo "<%@ Application Inherits=\"HelloFSharp.Global\" %>" >> Global.asax
5) copy Web.config mappings from http://www.servicestack.net/ServiceStack.Hello/
6) xsp4
*)
namespace HelloFSharp
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) = { HelloResponse.Result = "Hello, " + req.Name } :> Object
//Define the Web Services AppHost
type AppHost =
inherit AppHostBase
new() = { inherit AppHostBase("Hello F# Services", typeof<HelloService>.Assembly) }
override this.Configure container =
base.Routes
.Add<Hello>("/hello")
.Add<Hello>("/hello/{Name}") |> ignore
type Global =
inherit System.Web.HttpApplication
new() = { }
member x.Application_Start() =
let appHost = new AppHost()
appHost.Init()
<?xml version="1.0"?>
<configuration>
<system.web>
<httpHandlers>
<add path="*" type="ServiceStack.WebHost.Endpoints.ServiceStackHttpHandlerFactory, ServiceStack" verb="*"/>
</httpHandlers>
</system.web>
<!-- Required for IIS 7.0 -->
<system.webServer>
<handlers>
<add path="*" name="ServiceStack.Factory" type="ServiceStack.WebHost.Endpoints.ServiceStackHttpHandlerFactory, ServiceStack" verb="*" preCondition="integratedMode" resourceType="Unspecified" allowPathInfo="true" />
</handlers>
</system.webServer>
</configuration>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment