7
Answers

How to connect cross-domain web-client and signalr hub

ajay sharma

ajay sharma

7y
193
1
How to connect Web-Client with Hub when SignalR Hub has Different Domain and Web-Client has Different Domain. Eg: Web-Client (http://ABC.com/appLogin.html) and SignalR Hub (http://XYZ.com:/appLogin.html) in other hand we can also take localhost but different port number for both, then how we can connect our client to hub and send broadcast message to all.
Answers (7)
1
Laxmidhar Sahoo

Laxmidhar Sahoo

NA 2.3k 1.4k 7y
sir take to instances and two function .But I show you one function
  1. var SignalrConnection;    
  2. var ChatProxy;    
  3.    
  4. var SignalrConnection1;    
  5. var ChatProxy1;   
  6.    
  7. function Connect() {    
  8.     ChatServerUrl = "http://localhost:58416/";    
  9.     var ChatUrl = ChatServerUrl + "signalr";    
  10.     //This will hold the connection to the signalr hub     
  11.     SignalrConnection = $.hubConnection(ChatUrl, {    
  12.         useDefaultPath: false    
  13.     });    
  14.     ChatProxy = SignalrConnection.createHubProxy('ChatHub');    
  15.     
  16.     //This will be called by signalr     
  17.     ChatProxy.on("NotifyUser",function (temperature) {     
  18.         $('span').text(temperature);    
  19.     });    
  20.     
  21. //connecting the client to the signalr hub     
  22. SignalrConnection.start().done(function() {    
  23.         GetWeather();    
  24.         alert("Connected to Signalr Server");    
  25.     })    
  26.     .fail(function() {    
  27.         alert("failed in connecting to the signalr server");    
  28.     })    
  29.     
  30. }    
  31.     
  32. function GetWeather() {    
  33.     //calling the GetWeather function on the signalr server     
  34.     ChatProxy.invoke('get_weather');    
  35. }    
Accepted
0
ajay sharma

ajay sharma

NA 70 343 7y
Its done... Thanks for help. 
0
Laxmidhar Sahoo

Laxmidhar Sahoo

NA 2.3k 1.4k 7y
here I defined two connection object
 
var SignalrConnection;
var ChatProxy;
var SignalrConnection1;
var ChatProxy1;
 
first two inilitised by function
 
function Connect() {
ChatServerUrl = "http://localhost:58416/";
var ChatUrl = ChatServerUrl + "signalr";
 
like this connect second two
 
function Connect1() {
ChatServerUrl1 = "http://localhost:3456/"; //something like this
var ChatUrl1 = ChatServerUrl + "signalr";
0
ajay sharma

ajay sharma

NA 70 343 7y
Yes i need to connect using javascript.
 
Can you please share the HubClass and StartUp Class so that i can find my error.
 
I am doing same thing like your client javascript but my client unable to connect to Hub.
 
 
 
Thanks in Advance.
0
Laxmidhar Sahoo

Laxmidhar Sahoo

NA 2.3k 1.4k 7y
sir do you want connect using javascript
0
ajay sharma

ajay sharma

NA 70 343 7y
If i have to use web service which is SignalR .Net Client then what is the need of SignalR JavaScript Client.
0
Laxmidhar Sahoo

Laxmidhar Sahoo

NA 2.3k 1.4k 7y
sir use any web service