WCF 代理连接打开导致错误

标签 wcf wcf-client

我们使用托管在中间层 IIS 上的 WCF 服务并使用 WPF 客户端。 我们在生产日志中看到这些错误。从谷歌我被指向这里的链接http://kennyw.com/indigo/150这清楚地表明此错误与 MaxConcurrentSessions 有关。

下面的生产日志详细信息表明,当 WPF 客户端尝试使用 ICommunicationObject.Open() 打开 WCF 代理连接时,会发生错误 我们的生产系统上的此错误非常频繁地发生,但我无法在本地设置上重现此错误。我尝试将 MaxConcurrentSessions 更改为 1,然后打开 WPF 应用程序的 5 个实例,在 WPF 应用程序上,默认仪表板有一个计时器每 1 分钟运行一次以尝试获取数据,但我仍然无法重现此错误。

我的问题实际上是何时发生此错误,从上面的链接来看,它说当服务器压力过大时会发生这种情况,但在我上面的测试用例中应该已加载。我还需要能够重现此问题,甚至尝试修复。

如果我走在正确的道路上,有什么想法吗? MaxConcurrentSessions 是否是查看的正确位置以及如何在本地模拟它。请帮忙。

2/16/2012 4:10:40 PM:Information:Exception in the ServiceCall constructor:       System.ServiceModel.CommunicationException: 
  The socket connection was aborted. 
  This could be caused by an error processing your message or a receive timeout being   exceeded by the remote host, or an underlying network resource issue. 
  Local socket timeout was '00:00:59.9687730'. --->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.ServiceModel.Channels.SocketConnection.ReadCore(Byte[] buffer, Int32 offset, Int32 size, TimeSpan timeout, Boolean closing)
 --- End of inner exception stack trace ---
 Server stack trace: 
 at System.ServiceModel.Channels.SocketConnection.ReadCore(Byte[] buffer, Int32 offset, Int32 size, TimeSpan timeout, Boolean closing)
 at System.ServiceModel.Channels.SocketConnection.Read(Byte[] buffer, Int32 offset, Int32 size, TimeSpan timeout)
 at System.ServiceModel.Channels.DelegatingConnection.Read(Byte[] buffer, Int32 offset, Int32 size, TimeSpan timeout)
 at System.ServiceModel.Channels.ConnectionUpgradeHelper.InitiateUpgrade       (StreamUpgradeInitiator upgradeInitiator, IConnection& connection, ClientFramingDecoder decoder, IDefaultCommunicationTimeouts defaultTimeouts, TimeoutHelper& timeoutHelper)
 at System.ServiceModel.Channels.ClientFramingDuplexSessionChannel.SendPreamble(IConnection connection, ArraySegment`1 preamble, TimeoutHelper& timeoutHelper)
 at  System.ServiceModel.Channels.ClientFramingDuplexSessionChannel.DuplexConnectionPoolHelper.AcceptPooledConnection(IConnection connection, TimeoutHelper& timeoutHelper)
 at System.ServiceModel.Channels.ConnectionPoolHelper.EstablishConnection(TimeSpan timeout)
 at System.ServiceModel.Channels.ClientFramingDuplexSessionChannel.OnOpen(TimeSpan timeout)
 at System.ServiceModel.Channels.CommunicationObject.Open(TimeSpan timeout)
 at System.ServiceModel.Channels.ServiceChannel.OnOpen(TimeSpan timeout)
 at System.ServiceModel.Channels.CommunicationObject.Open(TimeSpan timeout)

最佳答案

问题的根本原因很可能是 WPF 应用程序中服务代理实例的不当处置。查看代理是如何实例化和处置的。

如果您的代码不遵循此 SO question 的答案中描述的模式之一那么你就没有正确释放 TCP 连接。当使用依赖于 TCP session 的绑定(bind)时,此问题最容易出现。

关于WCF 代理连接打开导致错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9804372/

相关文章:

c# - WCF - 发送请求的能力,其中字段可以按任何顺序排列

将 WSDL 中定义的响应反序列化为空消息时,WCF 使用 SOAP 会出错

.net - WCF生命周期事件

wcf - 如何将.NET代码库实现为服务层-在多个应用程序之间共享相同的BL/CRUD

c# - HttpWebRequest 与 HttpClient

java - android - WCF Rest服务通信

c# - ChannelFactory.Open VS IClientChannel.Open

wcf - 使用 WCF 服务防止 Http 重定向 307

c# - 如何在发出请求之前将 WCF Http 客户端绑定(bind)到特定的出站 IP 地址

带有 Jazzy UI 的 C# 应用程序