16

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
    });
TheJediCowboy
  • 7,686
  • 27
  • 121
  • 184
  • Did you set up cors support on the server? Specifically, you need to change your call to MapHubs to enable cross-domain requests. – William Xifaras May 20 '15 at 17:02
  • @WilliamXifaras Yes, I just edited my post. I have the `UseCors(CorsOptions.AllowAll)` – TheJediCowboy May 20 '15 at 17:17
  • Are you sure this is CORS that is causing the issue? I would try first without CORS (e.g. create a quick-and-dirty C# client) to make sure that the app is really working. Right now there might you might be trying to solve a wrong problem. – Pawel May 20 '15 at 18:58
  • I have run it locally flawlessly. I am not sure if its CORS issues or not. The only difference between when this app works and doesn't is if I deploy it to my VM, thus the client changes where it makes API calls to. – TheJediCowboy May 20 '15 at 20:35
  • 1
    How are you connecting to the VM service? I have exactly the same problem when going across NAT with port forwarding. Did you ever find out what was going wrong? – BlackSpy Aug 11 '15 at 10:37
  • @BlackSpy I did get across the issue and I am a bad OP and didn't post it. Now I am running into same issue and can't fix it. Did you end up figuring it out? – TheJediCowboy Nov 03 '15 at 16:02
  • @TheJediCowboy did you manage to solve it again? I have the same issue here, no solution found yet. – phifi Feb 12 '19 at 12:03

2 Answers2

9

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!

Melvin Iwuajoku
  • 101
  • 1
  • 5
8

I had same problem when connecting to signalR hub from my web project then I add

<add input="{REQUEST_URI}" pattern="^/(signalr)" negate="true" />

to rewrite rules in web.config file then signalR hub became reachable.

My client hub connection code is below

$.hubConnection('/signalr', { useDefaultPath: false });
cimey
  • 175
  • 3
  • 9