我们有一个WCF服务,在启动时通过Net.Pipes协议调用其他几个服务。该调用返回一个字符串列表, no Enum或复杂对象。
有时,我们会收到以下异常。
System.ServiceModel.CommunicationException: There was an error reading from the pipe: The pipe has been ended. (109, 0x6d). ---> System.IO.IOException: The read operation failed, see inner exception. ---> System.ServiceModel.CommunicationException: There was an error reading from the pipe: The pipe has been ended. (109, 0x6d). ---> System.IO.PipeException: There was an error reading from the pipe: The pipe has been ended. (109, 0x6d).
at System.ServiceModel.Channels.PipeConnection.FinishSyncRead(Boolean traceExceptionsAsErrors)
at System.ServiceModel.Channels.PipeConnection.Read(Byte[] buffer, Int32 offset, Int32 size, TimeSpan timeout)
--- End of inner exception stack trace ---
at System.ServiceModel.Channels.PipeConnection.Read(Byte[] buffer, Int32 offset, Int32 size, TimeSpan timeout)
at System.ServiceModel.Channels.ConnectionStream.Read(Byte[] buffer, Int32 offset, Int32 count)
at System.Net.FixedSizeReader.ReadPacket(Byte[] buffer, Int32 offset, Int32 count)
at System.Net.Security.NegotiateStream.StartFrameHeader(Byte[] buffer, Int32 offset, Int32 count, AsyncProtocolRequest asyncRequest)
at System.Net.Security.NegotiateStream.StartReading(Byte[] buffer, Int32 offset, Int32 count, AsyncProtocolRequest asyncRequest)
at System.Net.Security.NegotiateStream.ProcessRead(Byte[] buffer, Int32 offset, Int32 count, AsyncProtocolRequest asyncRequest)
--- End of inner exception stack trace ---
at System.Net.Security.NegotiateStream.ProcessRead(Byte[] buffer, Int32 offset, Int32 count, AsyncProtocolRequest asyncRequest)
at System.Net.Security.NegotiateStream.Read(Byte[] buffer, Int32 offset, Int32 count)
at System.ServiceModel.Channels.StreamConnection.Read(Byte[] buffer, Int32 offset, Int32 size, TimeSpan timeout)
--- End of inner exception stack trace ---
每次都不会发生。我几乎找不到任何对此错误的引用。
我想知道,为什么会发生这种情况以及如何防止它。
答案 0 :(得分:3)
可能的原因是,当Web服务尝试执行其工作时,您的应用程序池正在回收。
将其配置为在特定时间运行:
打开IIS管理器。
在“连接”窗格中,展开服务器节点,然后单击“应用程序” 池。
在“应用程序池”页面上,选择一个应用程序池,然后选择 单击“操作”窗格中的“回收”。
选择特定时间,然后在相应的框中键入时间 您希望应用程序池每天回收。例如, 键入11:30 AM或11:30 PM。
另一个原因可能是您的消息有效负载太大。增加服务器端和客户端的连接关闭时序。 BTW超时可能不仅是因为消息大小,而且因为系统太忙(CPU在100%时间一段时间),或者因为服务启动需要太多时间(在这种情况下预编译可能会有所帮助)。
为应用程序配置跟踪可能有助于诊断问题:https://msdn.microsoft.com/en-us/library/ms733025.aspx
答案 1 :(得分:-3)
为什么会这样?
由于错误已经说明:在读取操作有机会运行之前管道已关闭。
如何预防?
不要关闭Handle。手柄可以通过几种方式关闭:
Abort()
函数。Close()
函数。DuplicateAndClose()
函数。