SignalR "Error during negotiation request"

TheJediCowboy picture TheJediCowboy · May 20, 2015 · Viewed 21k times · Source

I have socket notification in my application which work great when I run locally, but when I deploy to my VM, it complains giving the following message.

Error: Error during negotiation request.
    at Object.signalR._.error (jquery.signalR.js:178)
    at signalR.fn.signalR.start.onFailed (jquery.signalR.js:644)
    at Object.signalR.fn.signalR.start.connection._.negotiateRequest.signalR.transports._logic.ajax.error (jquery.signalR.js:664)
    at n.Callbacks.j (jquery.js:3094)
    at Object.n.Callbacks.k.fireWith [as rejectWith] (jquery.js:3206)
    at x (jquery.js:8261)
    at XMLHttpRequest.n.ajaxTransport.k.cors.a.crossDomain.send.b (jquery.js:8600)

It is going across domains, but I believe I have gotten past the CORS issues, but I could be wrong.

EDIT

Here is additional info that I know will be asked.

Request:

GET http://path.to.my.vm/api/notifications/emmit/negotiate?clientProtocol=1.5&connectionData=%5B%7B%22name%22%3A%22testemitter%22%7D%5D&_=1432140840826 HTTP/1.1
Host: path.to.my.vm
Connection: keep-alive
Accept: text/plain, */*; q=0.01
Origin: http://localhost:8100
User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/42.0.2311.152 Safari/537.36
Content-Type: application/x-www-form-urlencoded; charset=UTF-8
Referer: http://localhost:8100/
Accept-Encoding: gzip, deflate, sdch
Accept-Language: en,fr;q=0.8,en-US;q=0.6

Response:

HTTP/1.1 500 Internal Server Error
Date: Wed, 20 May 2015 17:01:18 GMT
Server: Mono-HTTPAPI/1.0
Access-Control-Allow-Origin: *
Access-Control-Allow-Methods: POST, GET, OPTIONS, DELETE, PUT
Access-Control-Max-Age: 1000
Access-Control-Allow-Headers: x-requested-with, Content-Type, origin,authorization, accept, client-security-token
Content-Length: 0
Connection: close

EDIT

CORS support is setup on the server.

app.UseCors(CorsOptions.AllowAll);
app.MapSignalR("",new HubConfiguration()
    {
        EnableJavaScriptProxies = true
    });

Answer

Melvin Iwuajoku picture Melvin Iwuajoku · Feb 8, 2016

Also, make sure WebSockets is enabled on your signalr host. If it is a windows pc then check if websockets is enabled in Control Panel->Programs->Turn Windows features on or off.

If it is a windows server, Microsoft provides a step by step instructions on how to enable WebSockets http://www.iis.net/learn/get-started/whats-new-in-iis-8/iis-80-websocket-protocol-support.

I had CORS setup in Signalr config but still got the same error and it turned out that was my issue. Hope it helps!