[英]SignalR and SelfHost in F#
I think this will be quick answer, but I couldn't find the right answer during today. 我想这会很快回答,但我今天找不到合适的答案。 I trying create F# SignalR Self-Host application ( I followed this tutorial http://www.asp.net/signalr/overview/signalr-20/getting-started-with-signalr-20/tutorial-signalr-20-self-host ) 我尝试创建F#SignalR自我主机应用程序(我按照本教程http://www.asp.net/signalr/overview/signalr-20/getting-started-with-signalr-20/tutorial-signalr-20-self-主持人 )
The outcome is my application don't map signalr/hubs on my localhost, there is no error message (only from JavaScript file when it doesn't find client). 结果是我的应用程序没有在我的localhost上映射信号器/集线器,没有错误消息(只有当它没有找到客户端时才从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
I created C# application first and it does work perfectly, I assume my F# code is not right, but I cannot find that bug. 我首先创建了C#应用程序并且它确实工作得很好,我认为我的F#代码不对,但是我找不到那个bug。 For reference here is whole project: https://github.com/MartinBodocky/SignalRFSharp 这里是整个项目的参考: https : //github.com/MartinBodocky/SignalRFSharp
With the action overload of Start
, you don't have to make a whole type just for the start up configuration. 由于Start
的操作超载 ,您不必仅为启动配置创建整个类型。 Also you should definitely use use
instead of manually disposing. 你也一定要使用use
,而不是手动配置。
let startup (a:IAppBuilder) =
a.UseCors(CorsOptions.AllowAll) |> ignore
a.MapSignalR() |> ignore
use app = WebApp.Start(hostUrl, startup)
But that's just to make the code nicer, there is a problem with your hub code because the Dynamic module you brought can only invoke a method with one argument, use FSharp.Interop.Dynamic (in nuget) for a robust DLR ?
但这只是为了使代码更好,你的集线器代码存在问题,因为你带来的动态模块只能调用一个带有一个参数的方法,使用FSharp.Interop.Dynamic (在nuget中)来获得强大的DLR ?
Operator. 操作员。
open EkonBenefits.FSharp.Dynamic
type MyHub() =
inherit Hub()
member this.Send (name : string) (message : string) =
this.Clients.All?addMessage(name,message) |> ignore
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.