所以我刚开始玩 SignalR,但无法通过最基本的设置来让它工作。
我可以在下面的控制器中放置断点并查看客户端连接,但是客户端只是立即收到一个 WebException ,而没有任何关于问题所在的有用消息。这个简单的用法看起来有什么问题吗?
public class LiveController : PersistentConnection
{
public override Task ProcessRequestAsync(HostContext context)
{
return base.ProcessRequestAsync(context);
}
protected override Task OnConnectedAsync(IRequest request, string connectionId)
{
return base.OnConnectedAsync(request, connectionId);
}
protected override Task OnReceivedAsync(IRequest request, string connectionId, string data)
{
return base.OnReceivedAsync(request, connectionId, data);
}
protected override Connection CreateConnection(string connectionId, IEnumerable<string> signals, IEnumerable<string> groups)
{
return base.CreateConnection(connectionId, signals, groups);
}
}
这是客户端:
var connection = new Connection("http://192.168.0.102/live/");
connection.Start().ContinueWith(task =>
{
dispatcher.BeginInvoke(() =>
{
if (task.IsFaulted)
{
MessageBox.Show("Connection failed!");
}
else
{
MessageBox.Show("Success!");
}
});
});
还有一个例外:
System.Net.WebException occurred
HResult=-2146233079
Message=Exception of type 'System.Net.WebException' was thrown.
Source=System.Windows
StackTrace:
at System.Net.Browser.AsyncHelper.BeginOnUI(SendOrPostCallback beginMethod, Object state)
at System.Net.Browser.ClientHttpWebRequest.EndGetResponse(IAsyncResult asyncResult)
at Microsoft.AspNet.SignalR.Client.Http.HttpHelper.<>c__DisplayClass2.<GetHttpResponseAsync>b__0(IAsyncResult ar)
InnerException: System.Net.WebException
HResult=-2146233079
Message=Exception of type 'System.Net.WebException' was thrown.
Source=System.Windows
StackTrace:
at System.Net.Browser.ClientHttpWebRequest.InternalEndGetResponse(IAsyncResult asyncResult)
at System.Net.Browser.ClientHttpWebRequest.<>c__DisplayClasse.<EndGetResponse>b__d(Object sendState)
at System.Net.Browser.AsyncHelper.<>c__DisplayClass1.<BeginOnUI>b__0(Object sendState)
InnerException: