HttpSelfHostServer连接被主动拒绝

时间:2014-11-10 12:22:06

标签: c# .net https self-hosting

我在.NET中遇到HttpSelfHostServer的一个非常奇怪的问题:HTTP服务器工作正常12-24小时(我还没弄明白其失败的真正原因),之后它开始积极拒绝来自客户的连接。奇怪的是:甚至没有杀死服务器进程并重新启动它有帮助;只有干净地重新启动服务器计算机才能解决问题。我在3台不同的机器上重现了完全相同的行为,因此我的本地配置不是问题。对我而言,在Windows或.NET内部某处看起来像是一个问题。

这是我在客户端计算机上遇到的例外情况:

System.AggregateException: One or more errors occurred. ---> System.Net.Http.HttpRequestException: An error occurred while sending the request. ---> System.Net.WebException: Die zugrunde liegende Verbindung wurde geschlossen: Unerwarteter Fehler beim Senden.. ---> System.IO.IOException: Von der Übertragungsverbindung können keine Daten gelesen werden: Eine vorhandene Verbindung wurde vom Remotehost geschlossen. ---> System.Net.Sockets.SocketException: Eine vorhandene Verbindung wurde vom Remotehost geschlossen
   at System.Net.Sockets.Socket.EndReceive(IAsyncResult asyncResult)
   at System.Net.Sockets.NetworkStream.EndRead(IAsyncResult asyncResult)
   --- End of inner exception stack trace ---
   at System.Net.TlsStream.EndWrite(IAsyncResult asyncResult)
   at System.Net.PooledStream.EndWrite(IAsyncResult asyncResult)
   at System.Net.ConnectStream.WriteHeadersCallback(IAsyncResult ar)
   --- End of inner exception stack trace ---
   at System.Net.HttpWebRequest.EndGetRequestStream(IAsyncResult asyncResult, TransportContext& context)
   at System.Net.Http.HttpClientHandler.GetRequestStreamCallback(IAsyncResult ar)
   --- End of inner exception stack trace ---
   --- End of inner exception stack trace ---
   at System.Threading.Tasks.Task.ThrowIfExceptional(Boolean includeTaskCanceledExceptions)
   at System.Threading.Tasks.Task`1.GetResultCore(Boolean waitCompletionNotification)
   at System.Threading.Tasks.Task`1.get_Result()
   at ProELS.Car.Client.ProELSCarClient.SendMessageEnvelope(MessageEnvelope envelope, String host) in c:\Source\Kunden\ARB\ProELS.Car\ProELS.Car.Client\ProELSCarClient.cs:line 520
   at ProELS.Car.Client.ProELSCarClient.SendMessageEnvelope(MessageEnvelope envelope) in c:\Source\Kunden\ARB\ProELS.Car\ProELS.Car.Client\ProELSCarClient.cs:line 485
   at ProELS.Car.Client.ProELSCarClient.TestAuthentication() in c:\Source\Kunden\ARB\ProELS.Car\ProELS.Car.Client\ProELSCarClient.cs:line 239
   at ProELS.Car.TestClient.Form1.btnTryAuthentication_Click(Object sender, EventArgs e) in c:\Source\Kunden\ARB\ProELS.Car.TestClient\ProELS.Car.TestClient\Form1.cs:line 170
   at System.Windows.Forms.Control.OnClick(EventArgs e)
   at System.Windows.Forms.Button.OnClick(EventArgs e)
   at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
   at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
   at System.Windows.Forms.Control.WndProc(Message& m)
   at System.Windows.Forms.ButtonBase.WndProc(Message& m)
   at System.Windows.Forms.Button.WndProc(Message& m)
   at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
   at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
   at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
---> (Inner Exception #0) System.Net.Http.HttpRequestException: An error occurred while sending the request. ---> System.Net.WebException: Die zugrunde liegende Verbindung wurde geschlossen: Unerwarteter Fehler beim Senden.. ---> System.IO.IOException: Von der Übertragungsverbindung können keine Daten gelesen werden: Eine vorhandene Verbindung wurde vom Remotehost geschlossen. ---> System.Net.Sockets.SocketException: Eine vorhandene Verbindung wurde vom Remotehost geschlossen
   at System.Net.Sockets.Socket.EndReceive(IAsyncResult asyncResult)
   at System.Net.Sockets.NetworkStream.EndRead(IAsyncResult asyncResult)
   --- End of inner exception stack trace ---
   at System.Net.TlsStream.EndWrite(IAsyncResult asyncResult)
   at System.Net.PooledStream.EndWrite(IAsyncResult asyncResult)
   at System.Net.ConnectStream.WriteHeadersCallback(IAsyncResult ar)
   --- End of inner exception stack trace ---
   at System.Net.HttpWebRequest.EndGetRequestStream(IAsyncResult asyncResult, TransportContext& context)
   at System.Net.Http.HttpClientHandler.GetRequestStreamCallback(IAsyncResult ar)
   --- End of inner exception stack trace ---<---

这是我用来启动服务器的代码:

 private void StartCarServer()
        {

            HttpSelfHostServer carServer;
            var config = new ExtendedHttpSelfHostConfiguration("https://localhost:8082");

            config.Routes.MapHttpRoute("API Default", "api/{controller}/{id}", new { id = RouteParameter.Optional });
            config.Routes.MapHttpRoute("DefaultApiWithAction", "api/{controller}/{action}/{id}", new { id = RouteParameter.Optional });

            carServer = new HttpSelfHostServer(config);
            carServer.OpenAsync().Wait();
        }

我唯一可能的解释是,HttpSelfHostServer可能并非真正用于干净的TLS / SSL使用,因为它首先让它工作是一个非常糟糕的配置噩梦?

0 个答案:

没有答案