我的SignalR Hub运行时没有任何错误并保持连接状态。但是,我的服务器连接到集线器,但它失败了。服务器控制台消息是:
Server URL is: http://www.cypresspoint.com:3391/
17:55:54.5618418 - null - ChangeState(Disconnected, Connecting)
StateChanged to: Connecting
StateChanged to: Disconnected
17:55:55.3254814 - null - Disconnected
17:55:55.3264818 - null - Transport.Dispose()
17:55:55.3264818 - null - Closed
Server connection error Microsoft.AspNet.SignalR.Client.HttpClientException: StatusCode: 503, ReasonPhrase: 'Service Unavailable', Version: 1.1, Content: System.Net.Http.StreamContent, Headers:
{
Connection: close
Date: Sat, 11 Feb 2017 17:55:54 GMT
Server: Microsoft-HTTPAPI/2.0
Content-Length: 326
Content-Type: text/html; charset=us-ascii
}
at Microsoft.AspNet.SignalR.Client.Http.DefaultHttpClient.<>c__DisplayClass2.<Get>b__1(HttpResponseMessage responseMessage)
at Microsoft.AspNet.SignalR.TaskAsyncHelper.<>c__DisplayClass19`2.<Then>b__17(Task`1 t)
at Microsoft.AspNet.SignalR.TaskAsyncHelper.TaskRunners`2.<>c__DisplayClass3a.<RunTask>b__39(Task`1 t)
Enter return to exit
我对Hub的可重现代码是:
using System;
using System.Reflection;
using Microsoft.AspNet.SignalR;
using Microsoft.AspNet.SignalR.Hubs;
using Microsoft.Owin;
using Microsoft.Owin.Cors;
using Microsoft.Owin.Hosting;
using Owin;
using URL;
[assembly: OwinStartup(typeof(ConsoleHub.HubStartup))]
namespace ConsoleHub {
[HubName("TrinHub")]
public class HubStartup {
public void Configuration(IAppBuilder app) {
app.Map("/signalr", map => {
map.UseCors(CorsOptions.AllowAll);
var hubConfiguration = new HubConfiguration {
EnableDetailedErrors = true
};
app.MapSignalR("/signalr", hubConfiguration);
map.RunSignalR(hubConfiguration);
});
}
}
public class ConsoleHub : Hub {
public void TrinMessage(string message) {
Console.WriteLine(message);
var newMessage = string.Format(@"{0} has a length of: {1}", message, message.Length);
Clients.All.SendTrinMessage(newMessage);
}
private static void Run() {
try {
var url = SignalR_URL.Get();
Console.WriteLine(@"Hub URL is: {0}", url);
var options = new StartOptions(url) {
ServerFactory = "Microsoft.Owin.Host.HttpListener"
};
using (WebApp.Start<HubStartup>(options)) {
Console.WriteLine(@"HubProgram running at {0}", url);
Console.ReadLine();
}
} catch (TargetInvocationException ex) {
Console.WriteLine("HubProgram Error " + ex.InnerException);
}
}
private static void Main() {
Console.Title = "Hub";
Run();
Console.WriteLine("Enter return to exit");
Console.ReadLine();
}
}
}
我可重现的服务器代码是:
using System;
using System.Threading;
using Microsoft.AspNet.SignalR.Hubs;
using Microsoft.AspNet.SignalR.Client;
using URL;
namespace ConsoleServer {
[HubName("TrinHub")]
public class Server {
private static IHubProxy hub;
public static void Run() {
Console.Title = "Server";
try {
var url = SignalR_URL.Get();
Console.WriteLine(@"Server URL is: {0}", url);
System.Net.ServicePointManager.DefaultConnectionLimit = 10;
var hubConnection = new HubConnection(url) {
Credentials = System.Net.CredentialCache.DefaultNetworkCredentials,
TraceLevel = TraceLevels.All,
TraceWriter = Console.Out
};
hubConnection.StateChanged += (e) => { Console.WriteLine("StateChanged to: " + e.NewState); };
hub = hubConnection.CreateHubProxy("TrinHub");
hubConnection.Start().Wait();
} catch (Exception ex) {
Console.WriteLine("Server connection error " + ex.InnerException);
return;
}
hub.On("SendTrinMessage", x => Console.WriteLine("Message from server: " + x));
Console.WriteLine("Message send back to Hub");
while (true) {
var msg = DateTime.Now;
try {
hub.Invoke("TrinMessage", msg).Wait();
} catch (Exception ex) {
Console.WriteLine("Server Invoke Error " + ex.InnerException);
return;
}
Thread.Sleep(2000);
}
}
private static void Main() {
Run();
Console.WriteLine("Enter return to exit");
Console.ReadLine();
}
}
}
我开启了跟踪,输出如下所示。任何帮助或建议将不胜感激。
查尔斯
网络跟踪如下:
System.Net Information: 0 : [26048] Current OS installation type is 'Client'.
System.Net.Http Verbose: 0 : [26048] DefaultHttpHandler#46486038::.ctor()
System.Net.Http Verbose: 0 : [26048] Exiting DefaultHttpHandler#46486038::.ctor()
System.Net.Http Verbose: 0 : [26048] HttpClient#26879382::.ctor(DefaultHttpHandler#46486038)
System.Net.Http Information: 0 : [26048] Associating HttpClient#26879382 with DefaultHttpHandler#46486038
System.Net.Http Verbose: 0 : [26048] Exiting HttpClient#26879382::.ctor()
System.Net.Http Verbose: 0 : [26048] HttpClient#26879382::.ctor(DefaultHttpHandler#46486038)
System.Net.Http Verbose: 0 : [26048] Exiting HttpClient#26879382::.ctor()
System.Net.Http Verbose: 0 : [26048] DefaultHttpHandler#28312865::.ctor()
System.Net.Http Verbose: 0 : [26048] Exiting DefaultHttpHandler#28312865::.ctor()
System.Net.Http Verbose: 0 : [26048] HttpClient#19976800::.ctor(DefaultHttpHandler#28312865)
System.Net.Http Information: 0 : [26048] Associating HttpClient#19976800 with DefaultHttpHandler#28312865
System.Net.Http Verbose: 0 : [26048] Exiting HttpClient#19976800::.ctor()
System.Net.Http Verbose: 0 : [26048] HttpClient#19976800::.ctor(DefaultHttpHandler#28312865)
System.Net.Http Verbose: 0 : [26048] Exiting HttpClient#19976800::.ctor()
System.Net.Http Verbose: 0 : [26048] HttpRequestMessage#13742435::.ctor(Method: GET, Uri: 'http://www.cypresspoint.com:3391/signalr/negotiate?clientProtocol=1.4&connectionData=[{"Name":"TrinHub"}]')
System.Net.Http Verbose: 0 : [26048] Exiting HttpRequestMessage#13742435::.ctor()
System.Net.Http Verbose: 0 : [26048] HttpClient#19976800::SendAsync(HttpRequestMessage#13742435: Method: GET, RequestUri: 'http://www.cypresspoint.com:3391/signalr/negotiate?clientProtocol=1.4&connectionData=[{"Name":"TrinHub"}]', Version: 1.1, Content: <null>, Headers:
{
User-Agent: SignalR.Client.NET45/2.1.1.0
User-Agent: (Microsoft Windows NT 6.2.9200.0)
})
System.Net.Http Verbose: 0 : [26048] DefaultHttpHandler#28312865::SendAsync(HttpRequestMessage#13742435)
System.Net Verbose: 0 : [26048] HttpWebRequest#26568931::HttpWebRequest(http://www.cypresspoint.com:3391/signalr/negotiate?clientProtocol=1.4&connectionData=[{"Name":"TrinHub"}]#-536270730)
System.Net Information: 0 : [26048] RAS supported: True
System.Net Verbose: 0 : [26048] Exiting HttpWebRequest#26568931::HttpWebRequest()
System.Net Verbose: 0 : [26048] HttpWebRequest#26568931::HttpWebRequest(uri: 'http://www.cypresspoint.com:3391/signalr/negotiate?clientProtocol=1.4&connectionData=[{"Name":"TrinHub"}]', connectionGroupName: '28312865')
System.Net Verbose: 0 : [26048] Exiting HttpWebRequest#26568931::HttpWebRequest()
System.Net.Http Information: 0 : [26048] Associating HttpRequestMessage#13742435 with HttpWebRequest#26568931
System.Net.Http Verbose: 0 : [26048] Exiting DefaultHttpHandler#28312865::SendAsync() -> Task`1#34980106
System.Net.Http Verbose: 0 : [26048] Exiting HttpClient#19976800::SendAsync() -> Task`1#34980106
System.Net Verbose: 0 : [14452] HttpWebRequest#26568931::BeginGetResponse()
System.Net Error: 0 : [14452] Can't retrieve proxy settings for Uri 'http://www.cypresspoint.com:3391/signalr/negotiate?clientProtocol=1.4&connectionData=[{"Name":"TrinHub"}]'. Error code: 12180.
System.Net Verbose: 0 : [14452] ServicePoint#33156464::ServicePoint(www.cypresspoint.com:3391)
System.Net Information: 0 : [14452] Associating HttpWebRequest#26568931 with ServicePoint#33156464
System.Net Information: 0 : [14452] Associating Connection#15645912 with HttpWebRequest#26568931
System.Net.Sockets Verbose: 0 : [14452] Socket#32977404::Socket(AddressFamily#2)
System.Net.Sockets Verbose: 0 : [14452] Exiting Socket#32977404::Socket()
System.Net.Sockets Verbose: 0 : [14452] Socket#7588182::Socket(AddressFamily#23)
System.Net.Sockets Verbose: 0 : [14452] Exiting Socket#7588182::Socket()
System.Net.Sockets Verbose: 0 : [14452] DNS::TryInternalResolve(www.cypresspoint.com)
System.Net.Sockets Verbose: 0 : [14452] Socket#32977404::BeginConnectEx()
System.Net.Sockets Verbose: 0 : [14452] Socket#32977404::InternalBind(0.0.0.0:0#0)
System.Net.Sockets Verbose: 0 : [14452] Exiting Socket#32977404::InternalBind()
System.Net.Sockets Verbose: 0 : [14452] Exiting Socket#32977404::BeginConnectEx() -> ConnectOverlappedAsyncResult#5923895
System.Net.Sockets Verbose: 0 : [29372] Socket#32977404::EndConnect(ConnectOverlappedAsyncResult#5923895)
System.Net.Sockets Information: 0 : [29372] Socket#32977404 - Created connection from 108.220.213.113:53811 to 108.220.213.113:3391.
System.Net.Sockets Verbose: 0 : [29372] Exiting Socket#32977404::EndConnect()
System.Net Verbose: 0 : [14452] Exiting HttpWebRequest#26568931::BeginGetResponse() -> ContextAwareResult#65248697
System.Net.Sockets Verbose: 0 : [29372] Socket#7588182::Close()
System.Net.Sockets Verbose: 0 : [29372] Socket#7588182::Dispose()
System.Net.Sockets Verbose: 0 : [29372] Exiting Socket#7588182::Close()
System.Net Information: 0 : [29372] Connection#15645912 - Created connection from 108.220.213.113:53811 to 108.220.213.113:3391.
System.Net Information: 0 : [29372] Associating HttpWebRequest#26568931 with ConnectStream#20554616
System.Net Information: 0 : [29372] HttpWebRequest#26568931 - Request: GET /signalr/negotiate?clientProtocol=1.4&connectionData=[%7B%22Name%22:%22TrinHub%22%7D] HTTP/1.1
System.Net Information: 0 : [29372] ConnectStream#20554616 - Sending headers
{
User-Agent: SignalR.Client.NET45/2.1.1.0 (Microsoft Windows NT 6.2.9200.0)
Host: www.cypresspoint.com:3391
Connection: Keep-Alive
}.
System.Net.Sockets Verbose: 0 : [29372] Socket#32977404::UnsafeBeginSend()
System.Net.Sockets Verbose: 0 : [29372] Exiting Socket#32977404::UnsafeBeginSend() -> OverlappedAsyncResult#30762424
System.Net.Sockets Verbose: 0 : [22888] Data from Socket#32977404::PostCompletion
System.Net.Sockets Verbose: 0 : [22888] 00000000 : 47 45 54 20 2F 73 69 67-6E 61 6C 72 2F 6E 65 67 : GET /signalr/neg
System.Net.Sockets Verbose: 0 : [22888] 00000010 : 6F 74 69 61 74 65 3F 63-6C 69 65 6E 74 50 72 6F : otiate?clientPro
System.Net.Sockets Verbose: 0 : [22888] 00000020 : 74 6F 63 6F 6C 3D 31 2E-34 26 63 6F 6E 6E 65 63 : tocol=1.4&connec
System.Net.Sockets Verbose: 0 : [22888] 00000030 : 74 69 6F 6E 44 61 74 61-3D 5B 25 37 42 25 32 32 : tionData=[%7B%22
System.Net.Sockets Verbose: 0 : [22888] 00000040 : 4E 61 6D 65 25 32 32 3A-25 32 32 54 72 69 6E 48 : Name%22:%22TrinH
System.Net.Sockets Verbose: 0 : [22888] 00000050 : 75 62 25 32 32 25 37 44-5D 20 48 54 54 50 2F 31 : ub%22%7D] HTTP/1
System.Net.Sockets Verbose: 0 : [22888] 00000060 : 2E 31 0D 0A 55 73 65 72-2D 41 67 65 6E 74 3A 20 : .1..User-Agent:
System.Net.Sockets Verbose: 0 : [22888] 00000070 : 53 69 67 6E 61 6C 52 2E-43 6C 69 65 6E 74 2E 4E : SignalR.Client.N
System.Net.Sockets Verbose: 0 : [22888] 00000080 : 45 54 34 35 2F 32 2E 31-2E 31 2E 30 20 28 4D 69 : ET45/2.1.1.0 (Mi
System.Net.Sockets Verbose: 0 : [22888] 00000090 : 63 72 6F 73 6F 66 74 20-57 69 6E 64 6F 77 73 20 : crosoft Windows
System.Net.Sockets Verbose: 0 : [22888] 000000A0 : 4E 54 20 36 2E 32 2E 39-32 30 30 2E 30 29 0D 0A : NT 6.2.9200.0)..
System.Net.Sockets Verbose: 0 : [22888] 000000B0 : 48 6F 73 74 3A 20 77 77-77 2E 63 79 70 72 65 73 : Host: www.cypres
System.Net.Sockets Verbose: 0 : [22888] 000000C0 : 73 70 6F 69 6E 74 2E 63-6F 6D 3A 33 33 39 31 0D : spoint.com:3391.
System.Net.Sockets Verbose: 0 : [22888] 000000D0 : 0A 43 6F 6E 6E 65 63 74-69 6F 6E 3A 20 4B 65 65 : .Connection: Kee
System.Net.Sockets Verbose: 0 : [22888] 000000E0 : 70 2D 41 6C 69 76 65 0D-0A 0D 0A : p-Alive....
System.Net.Sockets Verbose: 0 : [22888] Socket#32977404::EndSend(OverlappedAsyncResult#30762424)
System.Net.Sockets Verbose: 0 : [22888] Exiting Socket#32977404::EndSend() -> Int32#235
System.Net.Sockets Verbose: 0 : [22888] Socket#32977404::UnsafeBeginReceive()
System.Net.Sockets Verbose: 0 : [22888] Exiting Socket#32977404::UnsafeBeginReceive() -> OverlappedAsyncResult#15510466
System.Net.Sockets Verbose: 0 : [29372] Data from Socket#32977404::PostCompletion
System.Net.Sockets Verbose: 0 : [29372] 00000000 : 48 54 54 50 2F 31 2E 31-20 35 30 33 20 53 65 72 : HTTP/1.1 503 Ser
System.Net.Sockets Verbose: 0 : [29372] 00000010 : 76 69 63 65 20 55 6E 61-76 61 69 6C 61 62 6C 65 : vice Unavailable
System.Net.Sockets Verbose: 0 : [29372] 00000020 : 0D 0A 43 6F 6E 74 65 6E-74 2D 54 79 70 65 3A 20 : ..Content-Type:
System.Net.Sockets Verbose: 0 : [29372] 00000030 : 74 65 78 74 2F 68 74 6D-6C 3B 20 63 68 61 72 73 : text/html; chars
System.Net.Sockets Verbose: 0 : [29372] 00000040 : 65 74 3D 75 73 2D 61 73-63 69 69 0D 0A 53 65 72 : et=us-ascii..Ser
System.Net.Sockets Verbose: 0 : [29372] 00000050 : 76 65 72 3A 20 4D 69 63-72 6F 73 6F 66 74 2D 48 : ver: Microsoft-H
System.Net.Sockets Verbose: 0 : [29372] 00000060 : 54 54 50 41 50 49 2F 32-2E 30 0D 0A 44 61 74 65 : TTPAPI/2.0..Date
System.Net.Sockets Verbose: 0 : [29372] 00000070 : 3A 20 53 61 74 2C 20 31-31 20 46 65 62 20 32 30 : : Sat, 11 Feb 20
System.Net.Sockets Verbose: 0 : [29372] 00000080 : 31 37 20 31 37 3A 35 35-3A 35 34 20 47 4D 54 0D : 17 17:55:54 GMT.
System.Net.Sockets Verbose: 0 : [29372] 00000090 : 0A 43 6F 6E 6E 65 63 74-69 6F 6E 3A 20 63 6C 6F : .Connection: clo
System.Net.Sockets Verbose: 0 : [29372] 000000A0 : 73 65 0D 0A 43 6F 6E 74-65 6E 74 2D 4C 65 6E 67 : se..Content-Leng
System.Net.Sockets Verbose: 0 : [29372] 000000B0 : 74 68 3A 20 33 32 36 0D-0A 0D 0A 3C 21 44 4F 43 : th: 326....<!DOC
System.Net.Sockets Verbose: 0 : [29372] 000000C0 : 54 59 50 45 20 48 54 4D-4C 20 50 55 42 4C 49 43 : TYPE HTML PUBLIC
System.Net.Sockets Verbose: 0 : [29372] 000000D0 : 20 22 2D 2F 2F 57 33 43-2F 2F 44 54 44 20 48 54 : "-//W3C//DTD HT
System.Net.Sockets Verbose: 0 : [29372] 000000E0 : 4D 4C 20 34 2E 30 31 2F-2F 45 4E 22 22 68 74 74 : ML 4.01//EN""htt
System.Net.Sockets Verbose: 0 : [29372] 000000F0 : 70 3A 2F 2F 77 77 77 2E-77 33 2E 6F 72 67 2F 54 : p://www.w3.org/T
System.Net.Sockets Verbose: 0 : [29372] 00000100 : 52 2F 68 74 6D 6C 34 2F-73 74 72 69 63 74 2E 64 : R/html4/strict.d
System.Net.Sockets Verbose: 0 : [29372] 00000110 : 74 64 22 3E 0D 0A 3C 48-54 4D 4C 3E 3C 48 45 41 : td">..<HTML><HEA
System.Net.Sockets Verbose: 0 : [29372] 00000120 : 44 3E 3C 54 49 54 4C 45-3E 53 65 72 76 69 63 65 : D><TITLE>Service
System.Net.Sockets Verbose: 0 : [29372] 00000130 : 20 55 6E 61 76 61 69 6C-61 62 6C 65 3C 2F 54 49 : Unavailable</TI
System.Net.Sockets Verbose: 0 : [29372] 00000140 : 54 4C 45 3E 0D 0A 3C 4D-45 54 41 20 48 54 54 50 : TLE>..<META HTTP
System.Net.Sockets Verbose: 0 : [29372] 00000150 : 2D 45 51 55 49 56 3D 22-43 6F 6E 74 65 6E 74 2D : -EQUIV="Content-
System.Net.Sockets Verbose: 0 : [29372] 00000160 : 54 79 70 65 22 20 43 6F-6E 74 65 6E 74 3D 22 74 : Type" Content="t
System.Net.Sockets Verbose: 0 : [29372] 00000170 : 65 78 74 2F 68 74 6D 6C-3B 20 63 68 61 72 73 65 : ext/html; charse
System.Net.Sockets Verbose: 0 : [29372] 00000180 : 74 3D 75 73 2D 61 73 63-69 69 22 3E 3C 2F 48 45 : t=us-ascii"></HE
System.Net.Sockets Verbose: 0 : [29372] 00000190 : 41 44 3E 0D 0A 3C 42 4F-44 59 3E 3C 68 32 3E 53 : AD>..<BODY><h2>S
System.Net.Sockets Verbose: 0 : [29372] 000001A0 : 65 72 76 69 63 65 20 55-6E 61 76 61 69 6C 61 62 : ervice Unavailab
System.Net.Sockets Verbose: 0 : [29372] 000001B0 : 6C 65 3C 2F 68 32 3E 0D-0A 3C 68 72 3E 3C 70 3E : le</h2>..<hr><p>
System.Net.Sockets Verbose: 0 : [29372] 000001C0 : 48 54 54 50 20 45 72 72-6F 72 20 35 30 33 2E 20 : HTTP Error 503.
System.Net.Sockets Verbose: 0 : [29372] 000001D0 : 54 68 65 20 73 65 72 76-69 63 65 20 69 73 20 75 : The service is u
System.Net.Sockets Verbose: 0 : [29372] 000001E0 : 6E 61 76 61 69 6C 61 62-6C 65 2E 3C 2F 70 3E 0D : navailable.</p>.
System.Net.Sockets Verbose: 0 : [29372] 000001F0 : 0A 3C 2F 42 4F 44 59 3E-3C 2F 48 54 4D 4C 3E 0D : .</BODY></HTML>.
System.Net.Sockets Verbose: 0 : [29372] 00000200 : 0A : .
System.Net.Sockets Verbose: 0 : [29372] Socket#32977404::EndReceive(OverlappedAsyncResult#15510466)
System.Net.Sockets Verbose: 0 : [29372] Exiting Socket#32977404::EndReceive() -> Int32#513
System.Net Information: 0 : [29372] Connection#15645912 - Received status line: Version=1.1, StatusCode=503, StatusDescription=Service Unavailable.
System.Net Information: 0 : [29372] Connection#15645912 - Received headers
{
Connection: close
Content-Length: 326
Content-Type: text/html; charset=us-ascii
Date: Sat, 11 Feb 2017 17:55:54 GMT
Server: Microsoft-HTTPAPI/2.0
}.
System.Net Information: 0 : [29372] ConnectStream#8627704::ConnectStream(Buffered 326 bytes.)
System.Net Information: 0 : [29372] Associating HttpWebRequest#26568931 with ConnectStream#8627704
System.Net Information: 0 : [29372] Associating HttpWebRequest#26568931 with HttpWebResponse#22017131
System.Net Warning: 0 : [29372] HttpWebRequest#26568931::() - The remote server returned an error: (503) Server Unavailable.
System.Net Verbose: 0 : [29372] HttpWebRequest#26568931::EndGetResponse()
System.Net Verbose: 0 : [29372] Exiting HttpWebRequest#26568931::EndGetResponse() -> HttpWebResponse#22017131
System.Net.Http Verbose: 0 : [29372] HttpResponseMessage#47016953::.ctor(StatusCode: 503, ReasonPhrase: '')
System.Net.Http Verbose: 0 : [29372] Exiting HttpResponseMessage#47016953::.ctor()
System.Net.Http Information: 0 : [29372] Associating HttpResponseMessage#47016953 with HttpRequestMessage#13742435
System.Net Verbose: 0 : [29372] HttpWebResponse#22017131::GetResponseStream()
System.Net Information: 0 : [29372] ContentLength=326
System.Net Verbose: 0 : [29372] Exiting HttpWebResponse#22017131::GetResponseStream() -> ConnectStream#8627704
System.Net.Http Verbose: 0 : [29372] StreamContent#62720642::.ctor()
System.Net.Http Verbose: 0 : [29372] Exiting StreamContent#62720642::.ctor()
System.Net.Http Information: 0 : [29372] Associating StreamContent#62720642 with WebExceptionWrapperStream#18306849
System.Net.Http Information: 0 : [29372] Associating HttpResponseMessage#47016953 with StreamContent#62720642
System.Net.Http Information: 0 : [29372] HttpClient#19976800 - Request for HttpRequestMessage#13742435 completed successfully. Returning response HttpResponseMessage#47016953: StatusCode: 503, ReasonPhrase: 'Service Unavailable', Version: 1.1, Content: System.Net.Http.StreamContent, Headers:
{
Connection: close
Date: Sat, 11 Feb 2017 17:55:54 GMT
Server: Microsoft-HTTPAPI/2.0
Content-Length: 326
Content-Type: text/html; charset=us-ascii
}