3
votes

I have a unique situation. I have developed an MVC 4 website and .NET client that connects to the site that is hosting a SignalR hub. The hubConnection object successfully connects to the hub. However, the hubProxy object which was created simply doesn't return back if I call hubProxy.Invoke("Test").Wait(); which my hub simply returns back a bool of true;

The interesting part is that when I run both the website and .net client locally through VS and IIS express, everything works correctly. When I run the website on a full 2008R2 IIS 7.5 server and the .net client on my laptop, it fails. Or more appropriately the thread simply stops at the HubProxy.Invoke("Test").Wait() and never returns (it just keeps running).

The even more interesting part is when I began running Fiddler to see what was happening or if the call made it through to the web server, the problem then resolves itself and everything works correctly.

It appears that somehow fiddler acting as a proxy for my .net client makes the hubProxy.Invoke() work. I would think that my HubConnection object would fail if I needed a proxy either way?? It's a little mis-leading to be able to connect to a hub connection successfully only to realize that a thread seems to run forever attempting to invoke a function on the hub proxy??

Can anyone clarify this behavior? And any suggestions on what I need to do to properly create the HubConnection/Proxy on the .net client side to call methods on the server?

Additionally, this may or may not be related. I noticed that if I host my website as:
http{s}//mywebsiteserver/mywebsite" and I can browse that way via a web browser, it WON'T work as a signalr connection string. I instead have to use the fully qualified DNS name of http{s}//mywebsiteserver.mydomainname.xyz/mywebsite

Any suggestions?

Thanks! Mike

4

4 Answers

7
votes

It seems to me that you need to set the ServicePointManager.DefaultConnectionLimit to a value greater than its default of 2 in the .NET client before starting your HubConnection or making any other HTTP requests. I have found 10 to be a reasonable limit for running a single SignalR HubConnection.

Normally, SignalR will only have 2 or less simultaneous HTTP connections, but this isn't always the case. I have found that running Fiddler will sometimes hide this issue, but I'm not sure why.

0
votes

Another explanation can be that you need to double check your url.

Let's say that your hub is on site.com and you have a 301 redirect from www.site.com to site.com.

Then SignalR may seem to establish a connection when you use

_hubConnection = new HubConnection("http://www.yoursite.com/signalr");

but in this case you must use

_hubConnection = new HubConnection("http://yoursite.com/signalr");

Otherwise _hubConnection.Start seems to work but _proxy.Invoke doesn't. I made this mistake myself. :)

0
votes

Also be sure that your method defined on the server is not static. I ran into that problem myself.

0
votes

In my case I was getting this web request error "The request failed with HTTP status 417: Expectation failed."

I solved this problem using on client:

ServicePointManager.Expect100Continue = false;

Read More: http://www.codeproject.com/Articles/94235/The-request-failed-with-HTTP-status-417-Expectatio