【发布时间】:2015-03-29 06:43:23
【问题描述】:
我正在尝试编写一个连接到具有信号器中心的现有网站的移动应用程序(角度)。我在网络服务器上配置了信号器:
// Branch the pipeline here for requests that start with "/signalr"
app.Map("/signalr", map =>
{
// Setup the CORS middleware to run before SignalR.
// By default this will allow all origins. You can
// configure the set of origins and/or http verbs by
// providing a cors options with a different policy.
map.UseCors(CorsOptions.AllowAll);
var hubConfiguration = new HubConfiguration
{
// You can enable JSONP by uncommenting line below.
// JSONP requests are insecure but some older browsers (and some
// versions of IE) require JSONP to work cross domain
// EnableJSONP = true
EnableDetailedErrors = true
};
// Run the SignalR pipeline. We're not using MapSignalR
// since this branch already runs under the "/signalr"
// path.
map.RunSignalR(hubConfiguration);
});
服务器在现场运行:http://localhost:62115/
我有另一个客户端应用程序在 http://localhost:4434/ 上运行,我正在尝试使用来自 http://localhost:62115/ 的信号器集线器:
$.connection.hub.url = "http://localhost:62115/signalr/hubs";
var queueProxy = $.connection.queueHub;
$.connection.hub.logging = true;
$.connection.hub.start()
.done(function () {
alert('yes');
})
.fail(function (e) {
alert(e);
});
但信号器无法连接。我收到错误无法成功初始化传输。以下是我的日志:
[16:19:58 GMT-0500 (Eastern Standard Time)] SignalR: Auto detected cross domain url.
jquery.signalR-2.1.1.js:81 [16:19:58 GMT-0500 (Eastern Standard Time)] SignalR: No hubs have been subscribed to. The client will not receive data from hubs. To fix, declare at least one client side function prior to connection start for each hub you wish to subscribe to.
jquery.signalR-2.1.1.js:81 [16:19:58 GMT-0500 (Eastern Standard Time)] SignalR: Negotiating with 'http://localhost:62115/signalr/hubs/negotiate?clientProtocol=1.4&connectionData=%5B%5D'.
jquery.signalR-2.1.1.js:81 [16:19:59 GMT-0500 (Eastern Standard Time)] SignalR: Connecting to websocket endpoint 'ws://localhost:62115/signalr/hubs/connect?transport=webSockets&clientProtocol=1.4&connectionToken=yNATl6%2FEQt710oI6ZGOV9%2F61Ry2SRjKQOgPDxKuXGSCYagKpbQKY5DOzRWdk1ggv6XaIm%2FJ2TUkkbmEkgCJyKHAKwy3ZweftP%2FYzRglLGe492Z4RDYY%2Btj8Aah3IhHIo&connectionData=%5B%5D&tid=2'.
jquery.signalR-2.1.1.js:81 [16:19:59 GMT-0500 (Eastern Standard Time)] SignalR: Websocket opened.
jquery.signalR-2.1.1.js:81 [16:20:04 GMT-0500 (Eastern Standard Time)] SignalR: webSockets timed out when trying to connect.
jquery.signalR-2.1.1.js:81 [16:20:04 GMT-0500 (Eastern Standard Time)] SignalR: Closing the Websocket.
jquery.signalR-2.1.1.js:81 [16:20:04 GMT-0500 (Eastern Standard Time)] SignalR: Attempting to connect to SSE endpoint 'http://localhost:62115/signalr/hubs/connect?transport=serverSentEvents&clie…AKwy3ZweftP%2FYzRglLGe492Z4RDYY%2Btj8Aah3IhHIo&connectionData=%5B%5D&tid=5'.
jquery.signalR-2.1.1.js:81 [16:20:04 GMT-0500 (Eastern Standard Time)] SignalR: EventSource connected.
jquery.signalR-2.1.1.js:81 [16:20:09 GMT-0500 (Eastern Standard Time)] SignalR: serverSentEvents timed out when trying to connect.
jquery.signalR-2.1.1.js:81 [16:20:09 GMT-0500 (Eastern Standard Time)] SignalR: EventSource calling close().
jquery.signalR-2.1.1.js:81 [16:20:09 GMT-0500 (Eastern Standard Time)] SignalR: Opening long polling request to 'http://localhost:62115/signalr/hubs/connect?transport=longPolling&clientPro…AKwy3ZweftP%2FYzRglLGe492Z4RDYY%2Btj8Aah3IhHIo&connectionData=%5B%5D&tid=6'.
jquery.signalR-2.1.1.js:81 [16:20:14 GMT-0500 (Eastern Standard Time)] SignalR: longPolling timed out when trying to connect.
jquery.signalR-2.1.1.js:81 [16:20:14 GMT-0500 (Eastern Standard Time)] SignalR: Aborted xhr request.
jquery.signalR-2.1.1.js:81 [16:20:24 GMT-0500 (Eastern Standard Time)] SignalR: Stopping connection.
jquery.signalR-2.1.1.js:81 [16:20:24 GMT-0500 (Eastern Standard Time)] SignalR: Fired ajax abort async = true.
【问题讨论】:
-
你能解决这个问题吗?
标签: c# angularjs asp.net-web-api signalr cors