SignalR和SelfHost在F#中的应用

7
我认为这可能是一个快速的答案,但在今天我找不到正确的答案。我试图创建一个F# SignalR自托管应用程序(我遵循了这个教程http://www.asp.net/signalr/overview/signalr-20/getting-started-with-signalr-20/tutorial-signalr-20-self-host)。我的应用程序的结果是无法映射localhost上的signalr / hubs,没有错误消息(仅在JavaScript文件中查找客户端时才有)。
namespace Program

open Owin
open Dynamic
open Microsoft.AspNet.SignalR
open Microsoft.AspNet.SignalR.Hubs
open Microsoft.Owin.Hosting
open Microsoft.Owin.Cors
open System
open System.Diagnostics

type MyHub =
   inherit Hub
   member x.Send (name : string) (message : string) =
       base.Clients.All?addMessage name message

type MyWebStartUp() =
    member x.Configuration (app :IAppBuilder) =
       app.UseCors CorsOptions.AllowAll |> ignore
       app.MapSignalR() |> ignore
       ()

module Starter =

[<EntryPoint>]
let main argv = 
    let hostUrl = "http://localhost:8085"
    let disposable = WebApp.Start<MyWebStartUp>(hostUrl)
    Console.WriteLine("Server running on "+ hostUrl)
    Console.ReadLine() |> ignore
    disposable.Dispose() 
    0 // return an integer exit code

我先创建了一个C#应用程序,运行得很完美。但我认为我的F#代码出了问题,只是找不到那个错误。这里提供整个项目的参考:https://github.com/MartinBodocky/SignalRFSharp

1个回答

6
使用Start动作重载,您无需为启动配置创建整个类型。此外,您应该绝对使用use而不是手动处理。
    let startup (a:IAppBuilder) =
       a.UseCors(CorsOptions.AllowAll) |> ignore
       a.MapSignalR() |> ignore
    use app = WebApp.Start(hostUrl, startup)

但这只是为了使代码更加清晰易读,你的中心代码存在一个问题,因为你使用的 Dynamic 模块仅能调用带有一个参数的方法,请使用 FSharp.Interop.Dynamic(nuget 中可获取)来使用一个强大的 DLR ? 运算符。

open EkonBenefits.FSharp.Dynamic
type MyHub() =
    inherit Hub()
    member this.Send (name : string) (message : string) =
        this.Clients.All?addMessage(name,message) |> ignore

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接