2012-07-06 181 views
1

我在我的MVC項目中安裝了signalR的客戶端和服務器;並且我可以從Web客戶端撥打我的集線器;SignalR:遠程服務器返回錯誤:(500)內部服務器錯誤

var testHub; 
$(function() { 
    // Setup SignalR 
    testHub = $.connection.myhub; 
    testHub.msg = function (ref) { 
     alert(ref); 
    }; 

    $.connection.hub.start(function() { 
     testHub.addToQueue("TESTMSG"); 
    }); 

}); 

而在控制器上,我需要在處理某些請求後調用我的集線器;所以我已經添加引用SignalR.Client.dll -Version(0.5.2.0)和Newtonsoft.Json.dll(4.5.0.0)運行時間4

我的控制器調用如下

var connection = new HubConnection("http://localhost:50439/"); 
     IHubProxy myHub = connection.CreateProxy("myhub"); 
     connection.Start().Wait(); 
     myHub.Invoke("addToQueue", new { message = "Hello world" }).ContinueWith(task => 
     { 


     }, TaskContinuationOptions.OnlyOnFaulted); 

而且我中心看起來如下:

[HubName("myhub")] 
public class QueueHub:Hub 
{ 
    public void addToQueue(string message) 
    { 
     Clients.msg(message); 
    } 
} 

但是,當從控制器調用發生時,系統得到如下錯誤: 錯誤讀取字符串。意外的令牌:StartObject。路徑 '',1號線,位置46,JsonSerializer

並詳細:

---> (Inner Exception #0) System.AggregateException: One or more errors occurred 
. ---> System.Net.WebException: The remote server returned an error: (500) Inter 
nal Server Error. 
    at System.Net.HttpWebRequest.EndGetResponse(IAsyncResult asyncResult) 
    at SignalR.Client.Http.HttpHelper.<>c__DisplayClass2.<GetHttpResponseAsync>b_ 
_0(IAsyncResult ar) in C:\Documents and Settings\mrafeeq\My Documents\Downloads\ 
SignalR-SignalR-0.5.0-231-g7808c90\SignalR-SignalR-7808c90\SignalR.Client\Http\H 
ttpHelper.cs:line 19 

回答

2

你調用服務器端方法不正確。你需要這樣做:

myHub.Invoke("addToQueue", "Hello world").ContinueWith(task => 
{ 


}, TaskContinuationOptions.OnlyOnFaulted); 
+0

謝謝大衛,所以簡單的電話。它解決了我的問題:-) – Rafeeq 2012-07-09 05:07:33

相關問題