WCF客户端代理抛出的TimeoutException

时间:2011-03-24 17:15:00

标签: wcf connection timeoutexception

我的问题与WCF不时抛出的System.TimeoutException有关:

  

System.TimeoutException:打开   操作内没有完成   分配超时00:00:00。时间   分配给这个操作可能有   是超时的一部分。   ---> System.TimeoutException:在00:00:00之后打开超时   建立一个运输会议   的net.tcp://192.168.1.100:50000 / TabletSvc /。   分配给此操作的时间   可能是一段时间的一部分   超时。 ---> System.TimeoutException:   连接到via   的net.tcp://192.168.1.100:50000 / TabletSvc /   00:00:00后超时。连接   尝试了0的1可用   地址()。检查RemoteAddress   您的频道并验证   此端点的DNS记录   对应有效的IP地址。该   分配给此操作的时间可能   是一段时间的一部分   超时。

随机行为的可能原因是什么?

WCF服务托管在Windows XP SP2上运行的.NET应用程序中。该应用程序为托管在不同计算机上的同一服务创建客户端代理。一个重要方面是该服务正在使用reliableSession和serviceThrottling。这些机器通过WiFi连接进行通信。

客户端和服务位于同一应用程序内的不同线程上。从这个角度来看,他们并不依赖于彼此。应该没有锁定。

我使用ping检查了机器之间的WiFi连接,看起来没问题。下一步是建立一个网络监视器,但由于它们是生产机器,它可能不会很快发生。

我考虑过将maxConcurrentSessions和maxConcurrentInstances都增加到50但没有时间来测试它。这是基于这样的想法:应用程序可能耗尽资源或达到影响托管服务的限制。

正如我所说,客户端代理无法仅不时打开连接。一分钟后的第二次尝试通常会成功。

以下是客户端和服务配置:

<system.serviceModel>
<client>
  <endpoint name="TabletSvcEndpoint" address="net.tcp://localhost:50000/TabletSvc/" binding="netTcpBinding" bindingConfiguration="TabletSvcBinding" contract="ITabletSvc">
   <identity>
    <dns value="localhost" />
   </identity>
  </endpoint>
</client>

<services>
 <service behaviorConfiguration="TabletSvcBehavior" name="TabletSvc">
   <endpoint name="TabletSvcEndpoint" address="" binding="netTcpBinding" bindingConfiguration="TabletSvcBinding" contract="ITabletSvc">
    <identity>
     <dns value="localhost" />
    </identity>
   </endpoint>
   <host>
    <baseAddresses>
     <add baseAddress="net.tcp://localhost:50000/TabletSvc/" />
        </baseAddresses>
   </host>
 </service>
</services>

<bindings>
 <netTcpBinding>
   <binding name="TabletSvcBinding" receiveTimeout="00:30:00" sendTimeout="00:00:30" closeTimeout="00:00:05" openTimeout="00:00:05" transactionFlow="false" transferMode="Buffered" transactionProtocol="OleTransactions" hostNameComparisonMode="StrongWildcard" listenBacklog="10" maxBufferPoolSize="524288" maxBufferSize="6553600" maxConnections="10" maxReceivedMessageSize="6553600">
    <readerQuotas maxDepth="32" maxStringContentLength="819200" maxArrayLength="163840" maxBytesPerRead="4096" maxNameTableCharCount="16384" />
    <reliableSession inactivityTimeout="00:01:00" ordered="true" enabled="true" />
    <security mode="None" />
  </binding>
 </netTcpBinding>
</bindings>

<behaviors>
 <serviceBehaviors>
  <behavior name="TabletSvcBehavior">
   <serviceDebug includeExceptionDetailInFaults="true" />
   <serviceThrottling maxConcurrentSessions="10" maxConcurrentInstances="10" maxConcurrentCalls="100" />
  </behavior>
 </serviceBehaviors>
</behaviors>

<diagnostics performanceCounters="Off" wmiProviderEnabled="False" >
  <messageLogging maxMessagesToLog="250" logEntireMessage="true" logMessagesAtServiceLevel="true" logMalformedMessages="true" logMessagesAtTransportLevel="true" />
</diagnostics>
</system.serviceModel>

以下是异常的堆栈跟踪:

10:20:18.3125 ClientChannel: Opening
10:20:48.8437 ClientChannel: Faulted
10:20:48.8593 Error: System.TimeoutException: The open operation did not complete within the allotted timeout of 00:00:00. The time allotted to this operation may have been a portion of a longer timeout. ---> System.TimeoutException: Open timed out after 00:00:00 while establishing a transport session to net.tcp://192.168.1.100:50000/TabletSvc/. The time allotted to this operation may have been a portion of a longer timeout. ---> System.TimeoutException: Connecting to via net.tcp://192.168.1.100:50000/TabletSvc/ timed out after 00:00:00. Connection attempts were made to 0 of 1 available addresses (). Check the RemoteAddress of your channel and verify that the DNS records for this endpoint correspond to valid IP Addresses. The time allotted to this operation may have been a portion of a longer timeout.
   at System.ServiceModel.Channels.SocketConnectionInitiator.CreateTimeoutException(Uri uri, TimeSpan timeout, IPAddress[] addresses, Int32 invalidAddressCount, SocketException innerException)
   at System.ServiceModel.Channels.SocketConnectionInitiator.Connect(Uri uri, TimeSpan timeout)
   at System.ServiceModel.Channels.BufferedConnectionInitiator.Connect(Uri uri, TimeSpan timeout)
   at System.ServiceModel.Channels.TracingConnectionInitiator.Connect(Uri uri, TimeSpan timeout)
   at System.ServiceModel.Channels.ConnectionPoolHelper.EstablishConnection(TimeSpan timeout)
   --- End of inner exception stack trace ---
   at System.ServiceModel.Channels.ConnectionPoolHelper.EstablishConnection(TimeSpan timeout)
   at System.ServiceModel.Channels.ClientFramingDuplexSessionChannel.OnOpen(TimeSpan timeout)
   --- End of inner exception stack trace ---

Server stack trace: 
   at System.ServiceModel.Channels.ClientFramingDuplexSessionChannel.OnOpen(TimeSpan timeout)
   at System.ServiceModel.Channels.CommunicationObject.Open(TimeSpan timeout)
   at System.ServiceModel.Channels.ReliableChannelBinder`1.ChannelSynchronizer.SyncWaiter.TryGetChannel()
   at System.ServiceModel.Channels.ReliableChannelBinder`1.ChannelSynchronizer.SyncWaiter.TryWait(TChannel& channel)
   at System.ServiceModel.Channels.ReliableChannelBinder`1.ChannelSynchronizer.TryGetChannel(Boolean canGetChannel, Boolean canCauseFault, TimeSpan timeout, MaskingMode maskingMode, TChannel& channel)
   at System.ServiceModel.Channels.ReliableChannelBinder`1.Send(Message message, TimeSpan timeout, MaskingMode maskingMode)
   at System.ServiceModel.Channels.SendReceiveReliableRequestor.OnRequest(Message request, TimeSpan timeout, Boolean last)
   at System.ServiceModel.Channels.ReliableRequestor.Request(TimeSpan timeout)
   at System.ServiceModel.Channels.ClientReliableSession.Open(TimeSpan timeout)
   at System.ServiceModel.Channels.ClientReliableDuplexSessionChannel.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)
   at System.ServiceModel.Channels.ServiceChannel.CallOpenOnce.System.ServiceModel.Channels.ServiceChannel.ICallOnce.Call(ServiceChannel channel, TimeSpan timeout)
   at System.ServiceModel.Channels.ServiceChannel.CallOnceManager.CallOnce(TimeSpan timeout, CallOnceManager cascade)
   at System.ServiceModel.Channels.ServiceChannel.EnsureOpened(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)

2 个答案:

答案 0 :(得分:1)

我也有这个问题。我用“127.0.0.1”替换“Localhost”解决了这个问题。

答案 1 :(得分:1)

在Windows XP SP2上运行的.NET应用程序

  

注意:对于Windows XP Professional,允许通过网络同时连接的其他计算机的最大数量为10。此限制包括所有传输和资源共享协议的组合。对于Windows XP Home Edition,允许通过网络同时连接的其他计算机的最大数量为5。

Microsoft KB

同时将此内容添加到您的app / web.config

<system.net>
   <connectionManagement>
     <add address="*" maxconnection="5000" />
   </connectionManagement>
</system.net> 

微软从未打算让XP中的网络堆栈处理这么多连接......