我試圖將客戶端連接到自託管的SignalR服務器。最簡單的可能樣本連接selfhosted signalR-server和客戶端?
我的服務器看起來是這樣的:
static void Main(string[] args)
{
string url = "http://localhost:8081/";
var server = new Server(url);
server.MapConnection<MyConnection>("/echo");
server.Start();
Console.WriteLine("Server running on {0}", url);
Console.ReadKey();
}
public class MyConnection : PersistentConnection
{
}
這是我能想出了最簡單的。客戶端看起來是這樣的:
static void Main(string[] args)
{
SignalR.Client.Connection conn = new SignalR.Client.Connection("http://localhost:8081/echo");
Task start = conn.Start();
start.Wait();
if (start.Status == TaskStatus.RanToCompletion)
{
Console.WriteLine("Connected");
}
Console.ReadKey();
}
我無法獲得上面的代碼工作。服務器啓動,但是當我運行客戶端代碼連接時出現錯誤:
遠程服務器返回錯誤:(500)內部服務器錯誤。
而服務器也給我一個錯誤:無法訪問一個處置對象。
我忘了什麼嗎?我究竟做錯了什麼?
編輯: 我得到的服務器上的錯誤是以下....
SignalRtest.vshost.exe錯誤:0:類型System.AggregateException「的第一次機會異常發生的mscorlib .dll TaskR引發的SignalR異常:System.AggregateException:發生了一個或多個錯誤。 ---> System.ObjectDisposedException:無法訪問處置的對象。 對象名稱:'System.Net.HttpListenerResponse'。 at System.Net.HttpListenerResponse.CheckDisposed() at System.Net.HttpListenerResponse.get_OutputStream() at SignalR.Hosting.Self.Infrastructure.ResponseExtensions。 <> C_ DisplayClass4.b _1(IAsyncResult的AR) 在System.Threading.Tasks.TaskFactory.FromAsyncCoreLogic(IAsyncResult的IAR,動作1 endMethod, TaskCompletionSource
1 TCS) ---內部異常堆棧跟蹤的結尾--- --- >(內部異常#0)System.ObjectDisposedException:無法訪問處置的對象。 對象名稱:'System.Net.HttpListenerResponse'。 at System.Net.HttpListenerResponse.CheckDisposed() at System.Net.HttpListenerResponse.get_OutputStream() at SignalR.Hosting.Self.Infrastructure.ResponseExtensions。 <> C_ DisplayClass4.b _1(IAsyncResult的AR) 在System.Threading.Tasks.TaskFactory.FromAsyncCoreLogic(IAsyncResult的IAR,動作1 endMethod, TaskCompletionSource
1 TCS)< ---
'client.vshost.exe'(管理(v4.0.30319)):已加載 'C:\ WINDOWS \裝配\ GAC_MSIL \ Microsoft.VisualStudio.DebuggerVisualizers \ 10.0.0.0__b03f5f7f11d50a3a \ Microsoft.VisualStudio.DebuggerVisualizers.dll'
你有沒有得到任何決議?我正在經歷完全相同的事情。 – Etch 2012-05-03 13:38:16
不,但在安裝vs11並運行在debugmode之後,上面的代碼運行..... – 2012-05-04 20:55:05