【发布时间】:2012-04-27 13:00:37
【问题描述】:
我正在尝试将客户端连接到自托管 SignalR 服务器。
我的服务器如下所示:
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) Internal Server Error.
服务器也给我一个错误:无法访问已处置的对象。
我忘记了什么吗?我做错了什么?
编辑: 我在服务器上遇到的错误如下......
SignalRtest.vshost.exe 错误:0:mscorlib.dll 中出现“System.AggregateException”类型的第一次机会异常
任务引发的 SignalR 异常:System.AggregateException:发生一个或多个错误。 ---> System.ObjectDisposedException:无法访问已处置的对象。
对象名称:“System.Net.HttpListenerResponse”。
在 System.Net.HttpListenerResponse.CheckDisposed()
在 System.Net.HttpListenerResponse.get_OutputStream()
在 SignalR.Hosting.Self.Infrastructure.ResponseExtensions.c_DisplayClass4.b_1(IAsyncResult ar)
在 System.Threading.Tasks.TaskFactory.FromAsyncCoreLogic(IAsyncResult iar,Action1 endMethod, TaskCompletionSource1 tcs)
--- 内部异常堆栈跟踪结束 ---
--->(内部异常 #0)System.ObjectDisposedException:无法访问已处置的对象。
对象名称:“System.Net.HttpListenerResponse”。
在 System.Net.HttpListenerResponse.CheckDisposed()
在 System.Net.HttpListenerResponse.get_OutputStream()
在 SignalR.Hosting.Self.Infrastructure.ResponseExtensions.c_DisplayClass4.b_1(IAsyncResult ar)
在 System.Threading.Tasks.TaskFactory.FromAsyncCoreLogic(IAsyncResult iar, Action1 endMethod, TaskCompletionSource1 tcs)
'client.vshost.exe'(托管 (v4.0.30319)):已加载 'C:\Windows\assembly\GAC_MSIL\Microsoft.VisualStudio.DebuggerVisualizers\10.0.0.0__b03f5f7f11d50a3a\Microsoft.VisualStudio.DebuggerVisualizers.dll'
【问题讨论】:
-
您对此有任何解决方案吗?我正在经历完全相同的事情。
-
没有,但是在安装 vs11 并在调试模式下运行后,上面的代码运行......