【问题标题】:WCF Server running under Mono intermittently crashes when responding to client request响应客户端请求时,在 Mono 下运行的 WCF 服务器间歇性崩溃
【发布时间】:2012-11-29 00:11:22
【问题描述】:

在 Mono 3.0 下的 Gentoo Linux (2.6.32-gentoo-r7) 上运行 WCF 服务器和 Windows 7 上的 WCF 客户端时,我遇到了相当间歇性的错误。

在客户端,我得到以下异常:

System.ServiceModel.CommunicationException: An error occurred while receiving the HTTP response to {myendpoint}. 
This could be due to the service endpoint binding not using the HTTP protocol. 
This could also be due to an HTTP request context being aborted by the server (possibly due to the service shutting down). 
See server logs for more details. 
---> System.Net.WebException: The underlying connection was closed: An unexpected error occurred on a receive. 
---> System.IO.IOException: Unable to read data from the transport connection: An existing connection was forcibly closed by the remote host.
---> System.Net.Sockets.SocketException: An existing connection was forcibly closed by the remote host     
  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.ServiceChannel.Call(String action, Boolean oneway, ProxyOperationRuntime operation, Object[] ins, Object[] outs)
  at System.ServiceModel.Channels.ServiceChannelProxy.InvokeService(IMethodCallMessage methodCall, ProxyOperationRuntime operation)
  at System.ServiceModel.Channels.ServiceChannelProxy.Invoke(IMessage message)
Exception rethrown at [0]:
  at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg)
  at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type)
  at {the WCF method call}....

在服务器端,我得到以下信息:

OnUnhandledException:Fatal Error: Read failure 
  InnerException:  interrupted
  at System.Net.Sockets.NetworkStream.Read (System.Byte[] buffer, Int32 offset, Int32 size) [0x00000] in <filename unknown>:0
  at System.Net.RequestStream.Read (System.Byte[] buffer, Int32 offset, Int32 count) [0x00000] in <filename unknown>:0
  at System.IO.StreamReader.ReadBuffer () [0x00000] in <filename unknown>:0
  at System.IO.StreamReader.Read (System.Char[] buffer, Int32 index, Int32 count) [0x00000] in <filename unknown>:0
  at Mono.Xml2.XmlTextReader.ReadTextReader (Int32 remained) [0x00000] in <filename unknown>:0
  at Mono.Xml2.XmlTextReader.PeekChar () [0x00000] in <filename unknown>:0
  at Mono.Xml2.XmlTextReader.ReadContent () [0x00000] in <filename unknown>:0
  at Mono.Xml2.XmlTextReader.Read () [0x00000] in <filename unknown>:0
  at System.Xml.XmlTextReader.Read () [0x00000] in <filename unknown>:0
  at System.Xml.XmlSimpleDictionaryReader.Read () [0x00000] in <filename unknown>:0
  at System.Xml.XmlReader.MoveToContent () [0x00000] in <filename unknown>:0
  at System.ServiceModel.Channels.XmlReaderMessage.ReadEnvelopeStart () [0x00000] in <filename unknown>:0
  at System.ServiceModel.Channels.XmlReaderMessage..ctor (System.ServiceModel.Channels.MessageVersion version, System.Xml.XmlDictionaryReader reader, Int32 maxSizeOfHeaders) [0x00000] in <filename unknown>:0
  at System.ServiceModel.Channels.Message.CreateMessage (System.Xml.XmlDictionaryReader envelopeReader, Int32 maxSizeOfHeaders, System.ServiceModel.Channels.MessageVersion version) [0x00000] in <filename unknown>:0
  at System.ServiceModel.Channels.TextMessageEncoder.ReadMessage (System.IO.Stream stream, Int32 maxSizeOfHeaders, System.String contentType) [0x00000] in <filename unknown>:0
  at System.ServiceModel.Channels.Http.HttpReplyChannel.CreatePostMessage (System.ServiceModel.Channels.Http.HttpContextInfo ctxi) [0x00000] in <filename unknown>:0
  at System.ServiceModel.Channels.Http.HttpReplyChannel.TryReceiveRequest (TimeSpan timeout, System.ServiceModel.Channels.RequestContext& context) [0x00000] in <filename unknown>:0
  at System.ServiceModel.Channels.ReplyChannelBase.<BeginTryReceiveRequest>m__10 (TimeSpan tout, System.ServiceModel.Channels.RequestContext& ctx) [0x00000] in <filename unknown>:0

在我看来,客户端尝试进行 WCF 方法调用,但服务器在读取请求的过程中出现了致命的读取错误。我猜在这种情况下,客户端会使用 CommunicationExpection 进行断言。但我不知道是什么导致了服务端的问题,如果有什么我可以做的,因为它发生在一个线程上,我不相信我有任何控制权。任何有关我如何分类此问题的线索将不胜感激。

【问题讨论】:

    标签: .net wcf mono


    【解决方案1】:

    我要做的第一件事是在你的服务器上抛出wireshark,这样你就可以捕获导致它失败的原始请求。

    收到请求后,您应该能够在调试时使用 SoapUi 或 Fiddler 重播它。

    仅仅能够看到错误的请求可能会很明显问题是什么。

    注意无效的 XML、过多的数据、超时等。

    【讨论】:

    • 谢谢,我们会试试看。
    • 好吧,让我们先从这里简单的事情开始——如果我们真的要查看这里的 http 流量,Fiddler 输出更容易查看,而且很少需要来自 Wireshark 的额外内容。跨度>
    • 但是在进入这些细节之前,让我们先做一些简单的事情:您在客户端和服务器上使用哪种配置? BasicHttpBinding 还是新的 .NET 4.5 BasicHttpsBinding?哪种安全性,您正在使用任何身份验证?如果您确实使用了其中任何一个,如果您关闭其中任何一个,问题是否会消失(如果确实如此,那已经将问题缩小了很多)。您是否在 app.config 中配置了任何其他行为?
    • 然后,让我们看看您尝试调用的方法。它的签名是什么(C# 中的返回类型和参数),你会在其中抛出任何异常吗?你能用一个简单的独立测试用例重现这个问题吗(那真的很棒)。
    • 从查看该堆栈跟踪来看,无论如何都可能需要 Fiddler 跟踪来调试它,但这仅表明任一方通过网络发送,而不是另一方期望接收的内容。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-04-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多