2
所以我剛開始玩SignalR,但無法擺脫讓它工作的最基本設置。SignalR客戶端獲取System.Net.WebException
我可以在下面的控制器中放置斷點並查看客戶端連接,但客戶端只是立即得到一個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: