Create a gist now

Instantly share code, notes, and snippets.

Embed
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