我正在尝试将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(服务器)
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(客户端)
<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(客户端)
//$.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!'); });;
});
我试过
Chrome控制台中的错误消息
无法加载资源:net :: ERR_CONNECTION_TIMED_OUT