所以我刚刚开始使用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: