在响应客户端请求时,在Mono下运行的WCF服务器会间歇性地崩溃

时间:2012-11-29 00:11:23

标签: .net wcf mono

在Mono 3.0下的Gentoo Linux(2.6.32-gentoo-r7)和Windows 7上的WCF客户端上运行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 进行断言。但是我不知道是什么原因造成了服务方面的问题,如果有什么我可以做的,因为它发生在一个线程上我不相信我有任何控制权。我将不胜感激,如何对这个问题进行分类。

1 个答案:

答案 0 :(得分:0)

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

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

只是能够看到错误的请求可能会使问题显而易见。

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