我试图将客户端连接到自托管的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