我正在尝试使用Javascript客户端连接到signalR服务器。我无法让JS客户端连接到服务器。我的调试输出显示客户端首先尝试订阅Websocket,然后SSE并发出Long Polling请求,所有这些都会超时。服务器是另一个signalR服务器的客户端,该连接没有问题。但是JS客户端无法连接。
我有以下套餐:
<package id="Microsoft.AspNet.SignalR" version="2.1.0" targetFramework="net451" />
<package id="Microsoft.AspNet.SignalR.Client" version="2.1.0" targetFramework="net451" />
<package id="Microsoft.AspNet.SignalR.Core" version="2.1.0" targetFramework="net451" />
<package id="Microsoft.AspNet.SignalR.JS" version="2.1.0" targetFramework="net451" />
<package id="Microsoft.AspNet.SignalR.Owin" version="1.2.1" targetFramework="net451" />
<package id="Microsoft.AspNet.SignalR.SystemWeb" version="2.1.0" targetFramework="net451" />
我的代码如下:
[assembly: OwinStartup(typeof(Startup))]
namespace CompanyPage
{
public class Startup
{
[ExceptionAspect]
public void Configuration(IAppBuilder app)
{
app.MapSignalR("/signalr", new HubConfiguration { EnableDetailedErrors = true });
}
}
}
protected void Session_Start(object sender, EventArgs e)
{
var context = GlobalHost.ConnectionManager.GetHubContext<ExchangeRate>();
context.Clients.All.insertOrder("TEST");
}
$(function () {
$.connection.hub.logging = true;
var chat = $.connection.exchangeRate;
chat.client.insertOrder = function(message) {
alert(message);
};
$.connection.hub.start().done(function() {
console.log("Connection Started");
});
});