Created
April 9, 2013 07:37
-
-
Save sergey-tihon/5343737 to your computer and use it in GitHub Desktop.
F#, ServiceStack + Project Service
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
open System | |
open ServiceStack.ServiceHost | |
open ServiceStack.WebHost.Endpoints | |
open ServiceStack.ServiceInterface | |
type Project() = | |
let mutable projectID = 0 | |
let mutable projectName = "" | |
let mutable companyName = "" | |
let mutable projectStatus = "" | |
member this.ProjectID with get() = projectID and set(pid) = projectID <-pid | |
member this.ProjectName with get() = projectName and set(pn) = projectName <- pn | |
member this.CompanyName with get() = companyName and set(cn) = companyName <- cn | |
member this.ProjectStatus with get() = projectStatus and set(ps) = projectStatus <-ps | |
type ProjectResponse() = | |
let mutable projects = List.empty<Project> | |
member this.Projects with get() = projects and set(pr) = projects <- pr | |
[<Route("/Project/{ProjectName}")>] | |
type ProjectRequest() = | |
let mutable projectName = "" | |
interface IReturn<ProjectResponse> | |
member this.ProjectName | |
with get() = projectName | |
and set(n) = projectName <- n | |
type ProjectService() = | |
inherit Service() | |
member this.Any (request:ProjectRequest) = | |
ProjectResponse( | |
Projects = [Project(ProjectName=request.ProjectName, ProjectID=1, CompanyName="A")]) | |
//Define the Web Services AppHost | |
type AppHost() = | |
inherit AppHostHttpListenerBase("Project F# Services", typeof<ProjectService>.Assembly) | |
override this.Configure container = ignore() | |
//Run it! | |
[<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