ServiceStack: F# Client Application

In the previous post “ServiceStack: New API – F# Sample (Web Service out of a web server)” we implemented a self-hosted service with ServiceStack. That service has multiple out-of-the-box endpoints, including a REST one.

The next interesting question is “How to call this service?”(preferably in a strongly-typed way). The answer is simple, ServiceStack team have already made ​​this for us.  We can reuse types that designed for server-side code to make client code prettier. ServiceStack provides a list of different service clients for client applications.

open System
open ServiceStack.ServiceHost
open ServiceStack.ServiceClient.Web

type HelloResponse = { Result:string }

type Hello() =
    interface IReturn<HelloResponse>
    member val Name = "" with get, set

let baseUri = "http://localhost:8080/"

// Option 1 : Json call
let jsonCall() =
    let client = new JsonServiceClient(baseUri)

// Option 2 : Xml call
let xmlCall() =
    let client = new XmlServiceClient(baseUri)

// Option 3: Jsv call
let jsvCall() =
    let client = new JsvServiceClient(baseUri)

let main args =
    printfn "Json call : %A" (jsonCall())
    printfn "Xml call : %A" (xmlCall())
    printfn "Jsv call : %A" (jsvCall())
    Console.ReadLine() |> ignore

2 thoughts on “ServiceStack: F# Client Application

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s