none
WCF 您的主机中的软件中止了一个已建立的连接 RRS feed

  • 问题

  • 系统上线快一年了,一直没有完整的查看过日志,一般都是出了问题去翻日志,现在把错误日志发到我的邮箱里面,才发现,基本上每天几十个WCF的连接错误。程序开了大概十几个线程,每个线程大概三分钟访问一次WCF。不同的线程里面都报过错误。

    首先这些服务在宏观上运行正常,也就是说,并不是每次都出错,因为该有的数据也都正常地来了,如果传输失败,下次传输成功的时候会弥补这次失败,所以,应该不是一直出错,是有一定的几率出错。所以,找不出是什么原因,我是真的解决不了了,需要专业的大神们分析一下,真的非常感谢。

    调用WCF服务的方式如下:

    if (client == null)
                {
                    client = new TClient();
                }
                try
                {
                    act(client);
                    client.Close();
                }
                catch (TimeoutException timeProblem)
                {
                    client.Abort();
                    throw timeProblem;
                }
                // Standard communication fault handler.
                catch (CommunicationException commProblem)
                {
                    client.Abort();
                    throw commProblem;
                }
                catch (Exception ex)
                {
                    client.Abort();
                    throw ex;
                }

    出现的错误:

    错误类型一

    WCF调用异常-The underlying connection was closed: A connection that was expected to be kept alive was closed by the server.
    System.ServiceModel.CommunicationException: The underlying connection was closed: A connection that was expected to be kept alive was closed by the server. ---> System.Net.WebException: The underlying connection was closed: A connection that was expected to be kept alive was closed by the server. ---> System.IO.IOException: Unable to read data from the transport connection: 您的主机中的软件中止了一个已建立的连接。. ---> System.Net.Sockets.SocketException: 您的主机中的软件中止了一个已建立的连接。
       at System.Net.Sockets.Socket.Receive(Byte[] buffer, Int32 offset, Int32 size, SocketFlags socketFlags)
       at System.Net.Sockets.NetworkStream.Read(Byte[] buffer, Int32 offset, Int32 size)
       --- End of inner exception stack trace ---
       at System.Net.Sockets.NetworkStream.Read(Byte[] buffer, Int32 offset, Int32 size)
       at System.Net.PooledStream.Read(Byte[] buffer, Int32 offset, Int32 size)
       at System.Net.Connection.SyncRead(HttpWebRequest request, Boolean userRetrievedStream, Boolean probeRead)
       --- End of inner exception stack trace ---
       at System.Net.HttpWebRequest.GetResponse()
       at System.ServiceModel.Channels.HttpChannelFactory.HttpRequestChannel.HttpChannelRequest.WaitForReply(TimeSpan timeout)
       --- End of inner exception stack trace ---
    
    Server stack trace: 
       at System.ServiceModel.Channels.HttpChannelUtilities.ProcessGetResponseWebException(WebException webException, HttpWebRequest request, HttpAbortReason abortReason)
       at System.ServiceModel.Channels.HttpChannelFactory.HttpRequestChannel.HttpChannelRequest.WaitForReply(TimeSpan timeout)
       at System.ServiceModel.Channels.RequestChannel.Request(Message message, TimeSpan timeout)
       at System.ServiceModel.Dispatcher.RequestChannelBinder.Request(Message message, TimeSpan timeout)
       at System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean oneway, ProxyOperationRuntime operation, Object[] ins, Object[] outs, TimeSpan timeout)
       at System.ServiceModel.Channels.ServiceChannelProxy.InvokeService(IMethodCallMessage methodCall, ProxyOperationRuntime operation)
       at System.ServiceModel.Channels.ServiceChannelProxy.Invoke(IMessage message)
    

    错误类型二

    WCF调用异常-The request channel timed out while waiting for a reply after 00:00:59.9843750. Increase the timeout value passed to the call to Request or increase the SendTimeout value on the Binding. The time allotted to this operation may have been a portion of a longer timeout.
    System.TimeoutException: The request channel timed out while waiting for a reply after 00:00:59.9843750. Increase the timeout value passed to the call to Request or increase the SendTimeout value on the Binding. The time allotted to this operation may have been a portion of a longer timeout. ---> System.TimeoutException: The HTTP request to 'http://****/***.svc' has exceeded the allotted timeout of 00:01:00 while reading the response. The time allotted to this operation may have been a portion of a longer timeout. ---> System.Net.WebException: The operation has timed out.
       at System.Net.ConnectStream.Read(Byte[] buffer, Int32 offset, Int32 size)
       at System.ServiceModel.Channels.PreReadStream.Read(Byte[] buffer, Int32 offset, Int32 count)
       at System.ServiceModel.Channels.HttpInput.WebResponseHttpInput.WebResponseInputStream.Read(Byte[] buffer, Int32 offset, Int32 count)
       --- End of inner exception stack trace ---
       at System.ServiceModel.Channels.HttpInput.WebResponseHttpInput.WebResponseInputStream.Read(Byte[] buffer, Int32 offset, Int32 count)
       at System.ServiceModel.Channels.MaxMessageSizeStream.Read(Byte[] buffer, Int32 offset, Int32 count)
       at System.ServiceModel.Channels.DetectEofStream.Read(Byte[] buffer, Int32 offset, Int32 count)
       at System.IO.BufferedStream.Read(Byte[] array, Int32 offset, Int32 count)
       at System.Xml.EncodingStreamWrapper.Read(Byte[] buffer, Int32 offset, Int32 count)
       at System.Xml.XmlBufferReader.TryEnsureBytes(Int32 count)
       at System.Xml.XmlUTF8TextReader.BufferElement()
       at System.Xml.XmlUTF8TextReader.ReadStartElement()
       at System.Xml.XmlUTF8TextReader.Read()
       at System.ServiceModel.Channels.ReceivedMessage.ReadStartEnvelope(XmlDictionaryReader reader)
       at System.ServiceModel.Channels.StreamedMessage..ctor(XmlDictionaryReader reader, Int32 maxSizeOfHeaders, MessageVersion desiredVersion)
       at System.ServiceModel.Channels.Message.CreateMessage(XmlDictionaryReader envelopeReader, Int32 maxSizeOfHeaders, MessageVersion version)
       at System.ServiceModel.Channels.TextMessageEncoderFactory.TextMessageEncoder.ReadMessage(Stream stream, Int32 maxSizeOfHeaders, String contentType)
       at System.ServiceModel.Channels.HttpInput.ReadStreamedMessage(Stream inputStream)
       at System.ServiceModel.Channels.HttpInput.ParseIncomingMessage(Exception& requestException)
       at System.ServiceModel.Channels.HttpChannelFactory.HttpRequestChannel.HttpChannelRequest.WaitForReply(TimeSpan timeout)
       at System.ServiceModel.Channels.RequestChannel.Request(Message message, TimeSpan timeout)
       --- End of inner exception stack trace ---
    
    

    错误类型三

    WCF调用异常-There was no endpoint listening at http://****/**.svc that could accept the message. This is often caused by an incorrect address or SOAP action. See InnerException, if present, for more details.
    System.ServiceModel.EndpointNotFoundException: There was no endpoint listening at http:/****/**.svc that could accept the message. This is often caused by an incorrect address or SOAP action. See InnerException, if present, for more details. ---> System.Net.WebException: Unable to connect to the remote server ---> System.Net.Sockets.SocketException: 由于连接方在一段时间后没有正确答复或连接的主机没有反应,连接尝试失败。 218.92.73.183:80
       at System.Net.Sockets.Socket.DoConnect(EndPoint endPointSnapshot, SocketAddress socketAddress)
       at System.Net.ServicePoint.ConnectSocketInternal(Boolean connectFailure, Socket s4, Socket s6, Socket& socket, IPAddress& address, ConnectSocketState state, IAsyncResult asyncResult, Int32 timeout, Exception& exception)
       --- End of inner exception stack trace ---
       at System.Net.HttpWebRequest.GetRequestStream(TransportContext& context)
       at System.Net.HttpWebRequest.GetRequestStream()
       at System.ServiceModel.Channels.HttpOutput.WebRequestHttpOutput.GetOutputStream()
       --- End of inner exception stack trace ---
    
    Server stack trace: 
       at System.ServiceModel.Channels.HttpOutput.WebRequestHttpOutput.GetOutputStream()
       at System.ServiceModel.Channels.HttpOutput.Send(TimeSpan timeout)
       at System.ServiceModel.Channels.HttpChannelFactory.HttpRequestChannel.HttpChannelRequest.SendRequest(Message message, TimeSpan timeout)
       at System.ServiceModel.Channels.RequestChannel.Request(Message message, TimeSpan timeout)
       at System.ServiceModel.Dispatcher.RequestChannelBinder.Request(Message message, TimeSpan timeout)
       at System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean oneway, ProxyOperationRuntime operation, Object[] ins, Object[] outs, TimeSpan timeout)
       at System.ServiceModel.Channels.ServiceChannelProxy.InvokeService(IMethodCallMessage methodCall, ProxyOperationRuntime operation)
       at System.ServiceModel.Channels.ServiceChannelProxy.Invoke(IMessage message)
    


    2016年7月4日 1:05

答案

  • 错误1 The underlying connection was closed 找不到服务器,服务器关闭了

    错误2 timed out  超时,可设置连接超时长一些

    错误3 There was no endpoint listening  找不到监听方法

    第一个错误是主要原因,可写一个日志,跟踪server 启动和关闭,client写下建立连接成功或失败事件


    专注于.NET ERP/CRM开发框架,C/S架构,SQL Server + ORM(LLBL Gen Pro) + Infragistics WinForms

    2016年7月4日 7:01

全部回复

  • 错误1 The underlying connection was closed 找不到服务器,服务器关闭了

    错误2 timed out  超时,可设置连接超时长一些

    错误3 There was no endpoint listening  找不到监听方法

    第一个错误是主要原因,可写一个日志,跟踪server 启动和关闭,client写下建立连接成功或失败事件


    专注于.NET ERP/CRM开发框架,C/S架构,SQL Server + ORM(LLBL Gen Pro) + Infragistics WinForms

    2016年7月4日 7:01
  • 确定了是网络 问题
    2016年9月7日 6:45