2014-07-14 89 views
0

當我有兩個域名的網站:問題創造跨域SignalR連接

  • a.com
  • b.com

b.com承載SignalR中心,和。 com嘗試創建與b.com的連接。

客戶端JS:

var connection = $.hubConnection('http://b.com/'); 
var notificationHubProxy = connection.createHubProxy('notificationHub'); 
$.connection.hub.logging = true; 
notificationHubProxy.client.resultReceived = function (result) { 
    console.log(result);object. 
} 

服務器eventHub:

public class NotificationHub : Hub 
{ 
    public void Hello() 
    { 
     Clients.All.hello(); 
    } 

    public string Echo() 
    { 
     return "Notification hub is running normally"; 
    } 

} 

但我總是在客戶端頁面上看到以下錯誤:

SCRIPT5007:無法設置屬性「resultReceived '未定義或 空引用。

當我檢查'notificationHubProxy。 客戶端'未定義。

哪裏出錯?

回答

1

這不是一個跨域問題。您正在混合動態代理無代理的方法。 $.hubConnectioncreateHubProxy來自無代理API,但.client僅適用於動態代理。檢查the documentation about both,你就可以修復它(我不會繼續使用代碼,因爲我不知道你真的想用哪種方法)。

+0

是的,這正是根本原因。 – smwikipedia