Last post Oct 12, 2013 06:58 PM by George.Stevens.99
Oct 09, 2013 09:45 AM|George.Stevens.99|LINK
I am wondering if it is possible to have SignalR Hubs hosted in the same Console App that also hosts a WCF service? I.e. the WCF Service host also hosts a SignalR hub.
The idea here is that the WCF service receives requests to push data to web clients from other WCF services in an SOA environment. Thus, the WCF service will use the GlobalHost construct of SignalR to do the push, which is possible since they share the
same process. The code in the WCF service does a push as follows:
// In the Constructor of the WCF service class.
IHubContext _Hub = GlobalHost.ConnectionManager.GetHubContext<PushHub>();
// In a method in the WCF service class, calling SignalR to push data
Is this supported by SignalR?
I've made a prototype that builds and runs OK. I have verified that the WCF service sees the Hubs. However I cannot navigate a browser to SignalR using the url used in the Host program in the following code
navigate to a non-existant port or url. I've been though the code with a fine tooth comb, but is there some interaction between WCF and SignalR that makes this bascially impossible?
Thanks in advance,
Oct 09, 2013 01:51 PM|George.Stevens.99|LINK
I have found and fixed the bug in the code that was rejecting the connection.
The new bug is now a HTTP 503 error. To debug this I implemented the code in the SignalR Self-Hosting Tutorial. And guess, what, I got the same error using
And when I run the Tutorial code the chat app does not send the message between browsers.
http://localhost:7897 in all places in the app -- in the js, the html and the C# code, preserving what ever suffixes were present. Basically I just changed the port number throughout the code from 8080 to 7897.
The Tutorial's chat app running in 2 browsers still do not communicate. However in FireBug's console there is some sort of error in the negotiation that makes the line appear red, although there is no HTTP error code. The console log then shows that SignalR
stopped after the negotiation failure.
What's going on that the simple Self-Hosting Tutorial will not run? I was running VisualStudio as Administrator.
how to fix this? Thanks in advance.
[13:09:11 GMT-0400 (Eastern Standard Time)] SignalR: Auto detected cross domain url. jquery....min.js (line 8)
[13:09:11 GMT-0400 (Eastern Standard Time)] SignalR: Client subscribed to hub 'myhub'. jquery....min.js (line 8)
[13:09:11 GMT-0400 (Eastern Standard Time)] SignalR: Negotiating with 'http://localhost:7897/signalr/negotiate?connectionData=%5B%7B%22name%22%3A%22myhub%22%7D%5D&clientProtocol=1.3'. jquery....min.js (line 8)
GET http://localhost:7897/signalr/negotiate?connecti...yhub%22%7D%5D&clientProtocol=1.3&_=1381338551398 200 OK 13ms jquery....min.js (line 4)
Wed, 09 Oct 2013 17:09:11 GMT
text/plain, */*; q=0.01
Mozilla/5.0 (Windows NT 6.1; WOW64; rv:24.0) Gecko/20100101 Firefox/24.0
[13:09:11 GMT-0400 (Eastern Standard Time)] SignalR: Stopping connection.
Oct 12, 2013 06:58 PM|George.Stevens.99|LINK
The problem is that I needed to allow CORS.
** The Self-Hosting Turorial does not say anything about that!! ** Please fix this tutorial and help us to avoid spending hours to figure this out on our own.
Here's how to enable CORS.
1. NuGet Microsoft.Owin.Cors and add that package to the project that has the Startup class in it.
2. In the Startup classes Configuration(IAppBuilder app) method, add the following line of code before the app.MapSignalR(); line:
3. Run your system and the negotiation failure will not be there, and your hubs will connect (to check, but a breakpoint in the override for OnConnected());