我正在尝试将Owin Self Hosted Signalr Service(使用TopShelf)发布到 生产环境 服务器,但似乎客户端在发布后无法连接到服务器 . 设置和代码几乎与您在互联网上找到的相同 .

Startup.cs

app.Map("/service", map =>
    {
        map.UseCors(CorsOptions.AllowAll);
        var hubConfiguration = new HubConfiguration
        {
            EnableJSONP = true,
            EnableDetailedErrors = true
        };
        map.RunSignalR(hubConfiguration);
    });
}

ServiceClass.cs (Server)

public bool StartService(HostControl hostControl)
    {
        //const string hostingUrl = "http://localhost:9000/";
        const string hostingUrl = "http://production-server:9000/"; 
        SignalR = WebApp.Start<Startup>(hostingUrl);
    }

Default.html (Client)

<head>
    <script src="Scripts/service.js"></script>
    <script src="Scripts/bootstrap.min.js"></script>
    <script src="Scripts/jquery-3.0.0.min.js"></script>
    <script src="Scripts/jquery.signalR-2.2.3.min.js"></script>

    <!--<script src="http://localhost:9000/service/hubs"></script>-->
    <script src="http://production-server:9000/service/hubs"></script>
</head>

service.js (Client)

//$.connection.hub.url = "http://localhost:9000/service";
$.connection.hub.url = "http://production-server:9000/service"; 

// Declare a proxy to reference the hub.
var sample = $.connection.service;
$.connection.hub.logging = true;  
    $.connection.hub.start().done(function() {
    }).fail(function () { console.log('Cannot Connect!'); });;
});

I have tried to

  • 使服务器和客户端都使用localhost url - > Works上面的代码

  • 使服务器和客户端都使用 生产环境 URL - >不工作

  • 使服务器代码使用localhost和客户端使用 生产环境 URL - >不工作

  • 在防火墙设置中允许端口9000,如此处所示How to Deploy Owin Self Hosted Application In Production?

Error Message in Chrome console

无法加载资源:net :: ERR_CONNECTION_TIMED_OUT