2012-03-21 67 views
2

我们正在使用中间层IIS上托管的WCF服务并使用WPF客户端。 我们在生产日志中看到这些错误。从谷歌我被指向这里的链接http://kennyw.com/indigo/150明确表示,这个错误是与MaxConcurrentSessions有关。WCF代理连接打开导致错误

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

我的问题是真的什么时候发生这种错误,从上面的链接说它发生这种情况时,服务器是紧张的,但在我的测试案例上面它应该已经加载。我也需要能够重现这个甚至试图修复。

任何想法,如果我在正确的道路上,是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) 

回答

2

有一个很好的机会,你的问题的根本原因是不正确的一次性服务代理实例在您的WPF应用程序。看看这些代理是如何实例化的,并且配置了

如果你的代码没有遵循这个SO question的答案中描述的模式之一,那么你不能正确释放TCP连接。当使用依赖于TCP会话的绑定时,此问题往往会弹出最多。

+0

我们使用的是使用块为每个连接重写的Idispose删除对象,这是一个干净的方式来做到这一点。 -------------------------------- public void TryCloseOrAbort(ICommunicationObject obj){if(obj!= null){if( obj.State!= CommunicationState.Faulted && obj.State!= CommunicationState.Closed){try {obj.Close(); } catch(CommunicationObjectFaultedException){obj.Abort(); } catch(TimeoutException){obj.Abort(); } catch(Exception){obj.Abort(); throw;}} else obj.Abort();}} – lloydom 2012-03-21 12:59:28

+0

我在代码中看到的唯一有点奇怪的地方是它可以在一个obj实例上调用Abort有obj。状态== CommunicationState.Closed。请尝试检查[ICommunicationObject文档](http://msdn.microsoft.com/zh-cn/library/ms789041.aspx)以查看是否可能导致处理过程中出现问题。 – 2012-03-21 13:29:39

+0

感谢您的回复sixto,链接说,关闭通信状态值调用中止不会导致问题“如果当前状态为”关闭“或者对象已在”之前终止“,则Abort()方法不会执行任何操作,因此它不应该导致我看到的这个问题。嗯,你认为这个错误只是因为使用块吗? -------------------------------------------------- -Using(var svc = new ServiceCall (endpointName)){serviceCallType = svc.GetType(); //调用调用者实现的服务调用serviceCallBody(svc); } – lloydom 2012-03-22 08:36:23

0

可能有几个原因导致该错误。 MaxConcurrentSessions就是其中之一。

在服务器端和客户端的配置文件中一定要增加receiveTimeout的SendTimeout。您可能会超出这些参数允许的时间。

您需要确保服务器和客户端对这些字段具有相同的配置值。如果你只改变其中一个,另一个可能会提前超时。

除此之外,他们的XML配置的MS参考资料如下,并可能帮助您找到造成问题的原因。

http://msdn.microsoft.com/en-us/library/ms731354.aspx

0

把这一行在App.Config中在消费者身边

<system.net> 
    <defaultProxy useDefaultCredentials="true"> 
    <proxy usesystemdefault="True" bypassonlocal="True"/> 
    </defaultProxy> 
</system.net> 
相关问题