Skip to content

Instantly share code, notes, and snippets.

@filipw
Last active May 3, 2016 18:02
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save filipw/9846071 to your computer and use it in GitHub Desktop.
Save filipw/9846071 to your computer and use it in GitHub Desktop.
ASP.NET Web API hosted in Azure Worker Role with OWIN in F#
namespace WebApi.AzureWorker
open Owin
open System
open System.Diagnostics
open System.Net
open System.Threading
open System.Net.Http
open System.Web.Http
open Microsoft.Owin.Hosting
open Microsoft.WindowsAzure.ServiceRuntime
type TestController() =
inherit ApiController()
[<Route("test")>]
member x.Get() = "Hello Azure!"
type WorkerRole() =
inherit RoleEntryPoint()
let mutable webApp = None
override w.Run() =
while(true) do
Thread.Sleep(10000)
Trace.TraceInformation("Working", "Information")
override w.OnStart() =
ServicePointManager.DefaultConnectionLimit <- 12
let endpoint = RoleEnvironment.CurrentRoleInstance.InstanceEndpoints.["Default"]
let uri = sprintf "%s://%O" endpoint.Protocol endpoint.IPEndpoint
webApp <- Some(WebApp.Start(uri, fun app ->
let config = new HttpConfiguration()
config.MapHttpAttributeRoutes()
app.UseWebApi(config) |> ignore
))
base.OnStart()
override w.OnStop() =
match webApp with
| Some x -> x.Dispose() |> ignore
| None -> ()
base.OnStop()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment