【问题标题】:WCF client getting a TimeoutException (and I AM closing my connections)WCF 客户端收到 TimeoutException(我正在关闭我的连接)
【发布时间】:2010-10-27 19:14:56
【问题描述】:

事情是这样的... 我已经在这个问题上工作了很长时间,但没有运气

我有一个托管在 IIS 上的 WCF 服务(我也在控制台主机中尝试过,我得到了相同的行为),我通过我的 scvutil 创建的代理调用它,并且服务在几次(很少调用)后无法响应。

但是,这里有一些线索:
1- 它只发生在测试环境中(而不是我的开发机器上托管的服务),数字!
2- 我异步调用服务 (client.MyServiceAsync)
3-这是最棘手的一个......如果我运行 fiddler 来查看发生了什么,客户端工作并且永远不会失败,当然,我关闭 fiddler(甚至没有重新启动客户端)

到目前为止,我不知道发生了什么。我开始认为服务器(Win2003)可能有某种“防御者”阻止进一步的连接,这可能吗?请相信我,当我说我在每次通话后都会关闭客户端时,实际上是在我得到服务器的响应之后,因为我使用的是异步调用。

任何提示或建议将不胜感激。 问候,

编辑:我认为这可能是有用的信息: 我在两端都启用了跟踪,但没有运气。
在服务器端,我看到连接来来去去......在某些时候没有更多连接进入。而在客户端,我看到连接工作,直到其中一个抛出 TimeoutException......这就是我得到的全部/p>

【问题讨论】:

  • 客户端和测试服务器之间有哪些网元?有 NAT 设备吗?
  • 不,我在同一个本地网络中,我们之间没有任何关系
  • 很可能是配置问题。我知道您可以将超时设置为您想要的任何值。我没有带我的 WCF 书,但如果您附近有书店,请在午餐时查看 Juval Lowy 的“Programming WCF Services”。另外,我确信 MSDN 上有关于在配置部分设置超时值(客户端和服务器)的信息。
  • 这不是超时问题,而是资源没有被释放...我每次都调用相同的服务

标签: wcf proxy asynchronous timeout fiddler


【解决方案1】:

WCF 支持服务限制。这允许您限制可以同时运行的消息/连接/实例的数量。在 MSDN 上搜索 ServiceThrottle。

您在应用配置中指定您的 ServiceThrottle,如下所示:

 <behaviors>
      <serviceBehaviors>
        <behavior  name="Throttled">
          <serviceThrottling 
            maxConcurrentCalls="1" 
            maxConcurrentSessions="2200" 
            maxConcurrentInstances="1"
          />
        </behavior>
      </serviceBehaviors>
    </behaviors>

如果您怀疑限制是问题所在,请在调试器或转储中查找 ServiceThrottle 对象。这是在转储上使用 cdb 的示例:

转储服务主机

0:000> !do 0000000001647fc0
Name: System.ServiceModel.ServiceHost
MethodTable: 000007feef98a7f0
EEClass: 000007feef352d60
Size: 248(0xf8) bytes
 (D:\Windows\assembly\GAC_MSIL\System.ServiceModel\3.0.0.0__b77a5c561934e089\System.ServiceModel.dll)
Fields:
              MT    Field   Offset                 Type VT     Attr            Value Name
000007fef23d5918  400098a       4c       System.Boolean  1 instance                0 aborted
000007fef23d5918  400098b       4d       System.Boolean  1 instance                0 closeCalled
000007feef93aa00  400098c        8 ...ct+ExceptionQueue  0 instance 0000000000000000 exceptionQueue
000007fef23d6038  400098d       10        System.Object  0 instance 0000000001648188 mutex
000007fef23d5918  400098e       4e       System.Boolean  1 instance                0 onClosingCalled
000007fef23d5918  400098f       4f       System.Boolean  1 instance                0 onClosedCalled
000007fef23d5918  4000990       50       System.Boolean  1 instance                1 onOpeningCalled
000007fef23d5918  4000991       51       System.Boolean  1 instance                1 onOpenedCalled
000007fef23d5918  4000992       52       System.Boolean  1 instance                0 raisedClosed
000007fef23d5918  4000993       53       System.Boolean  1 instance                0 raisedClosing
000007fef23d5918  4000994       54       System.Boolean  1 instance                0 raisedFaulted
000007fef23d5918  4000995       55       System.Boolean  1 instance                1 traceOpenAndClose
000007fef23d6038  4000996       18        System.Object  0 instance 0000000001647fc0 eventSender
000007feef929a60  4000997       48         System.Int32  1 instance                2 state
000007fef23ce158  4000998       20  System.EventHandler  0 instance 0000000000000000 Closed
000007fef23ce158  4000999       28  System.EventHandler  0 instance 0000000000000000 Closing
000007fef23ce158  400099a       30  System.EventHandler  0 instance 0000000001648660 Faulted
000007fef23ce158  400099b       38  System.EventHandler  0 instance 0000000000000000 Opened
000007fef23ce158  400099c       40  System.EventHandler  0 instance 0000000000000000 Opening
000007fef23d5918  4002e78       56       System.Boolean  1 instance                1 initializeDescriptionHasFinished
000007feef981300  4002e79       58 ...meKeyedCollection  0 instance 00000000016481a0 baseAddresses
000007feef981500  4002e7a       60 ...patcherCollection  0 instance 0000000001648220 channelDispatchers
000007fef2416b80  4002e7b       c0      System.TimeSpan  1 instance 0000000001648080 closeTimeout
000007feef980e70  4002e7c       68 ...erviceDescription  0 instance 0000000001656e28 description
0000000000000000  4002e7d       70                       0 instance 0000000001648290 extensions
0000000000000000  4002e7e       78                       0 instance 0000000000000000 externalBaseAddresses
0000000000000000  4002e7f       80                       0 instance 000000000166cf80 implementedContracts
000007feef989770  4002e80       88 ...nceContextManager  0 instance 0000000001648300 instances
000007fef2416b80  4002e81       c8      System.TimeSpan  1 instance 0000000001648088 openTimeout
000007feef8e9890  4002e82       90 ...rformanceCounters  0 instance 0000000000000000 servicePerformanceCounters
000007feef98b708  4002e83       98 ...rformanceCounters  0 instance 000000000171c590 defaultPerformanceCounters
000007feef981a18  4002e84       a0 ...r.ServiceThrottle  0 instance 0000000001648340 serviceThrottle
000007feef980c20  4002e85       a8 ...erviceCredentials  0 instance 0000000001800ed0 readOnlyCredentials
000007feef980d58  4002e86       b0 ...orizationBehavior  0 instance 0000000001801240 readOnlyAuthorization
0000000000000000  4002e87       b8                       0 instance 0000000000000000 UnknownMessageReceived
000007fef53bc640  4002e77      f80           System.Uri  0   static 0000000001648110 EmptyUri
000007fef23d6038  40032cc       d0        System.Object  0 instance 00000000015be070 singletonInstance
000007fef23d8420  40032cd       d8          System.Type  0 instance 00000000016486a0 serviceType
000007feef981ee0  40032ce       e0 ...ontractCollection  0 instance 0000000001657468 reflectedContracts
000007fef23d1000  40032cf       e8   System.IDisposable  0 instance 0000000000000000 disposableInstance

转储 ServiceHost 的限制信息

0:000> !do 0000000001648340
Name: System.ServiceModel.Dispatcher.ServiceThrottle
MethodTable: 000007feef981a18
EEClass: 000007feef34c2d8
Size: 72(0x48) bytes
 (D:\Windows\assembly\GAC_MSIL\System.ServiceModel\3.0.0.0__b77a5c561934e089\System.ServiceModel.dll)
Fields:
              MT    Field   Offset                 Type VT     Attr            Value Name
000007feef981a90  400371d        8 ...cher.FlowThrottle  0 instance 00000000016484a8 calls
000007feef981a90  400371e       10 ...cher.FlowThrottle  0 instance 00000000016485d8 sessions
000007feef902140  400371f       18 ...her.QuotaThrottle  0 instance 0000000000000000 dynamic
000007feef981a90  4003720       20 ...cher.FlowThrottle  0 instance 0000000001779f80 instanceContexts
000007feef9808c8  4003721       28 ...l.ServiceHostBase  0 instance 0000000001647fc0 host
000007fef23d5918  4003722       38       System.Boolean  1 instance                1 isActive
000007fef23d6038  4003723       30        System.Object  0 instance 0000000001648410 thisLock

转储会话限制信息

0:000> !do 00000000016485d8
Name: System.ServiceModel.Dispatcher.FlowThrottle
MethodTable: 000007feef981a90
EEClass: 000007feef34c390
Size: 64(0x40) bytes
 (D:\Windows\assembly\GAC_MSIL\System.ServiceModel\3.0.0.0__b77a5c561934e089\System.ServiceModel.dll)
Fields:
              MT    Field   Offset                 Type VT     Attr            Value Name
000007fef23dd9b8  40034f5       30         System.Int32  1 instance             2220 capacity
000007fef23dd9b8  40034f6       34         System.Int32  1 instance             **2220 count
000007fef23d6038  40034f7        8        System.Object  0 instance 0000000001648618 mutex
000007fef23c4d70  40034f8       10 ...ding.WaitCallback  0 instance 0000000001648598 release
0000000000000000  40034f9       18                       0 instance 0000000001648630 waiters
000007fef23d6748  40034fa       20        System.String  0 instance 00000000016483c8 propertyName
000007fef23d6748  40034fb       28        System.String  0 instance 0000000001648550 configName
0:000>

【讨论】:

  • -1:我看不出你的答案与问题有什么关系,特别是因为 OP 已经解决了问题。
【解决方案2】:

好的,下面是我解决问题的方法,以防有人遇到同样的问题。
我的服务,异步调用,返回一个流,这个流没有被释放到客户端,因此,代理没有被释放。

感谢大家的 cmets。他们让我找到了解决方案,因为我以前没有听说过任何新内容。

【讨论】:

    【解决方案3】:

    最好的办法是在客户端和服务上都启用跟踪,以查看控制流。至少,您将对 WCF 正在执行的操作有所了解。

    以下是有关启用跟踪的信息: http://msdn.microsoft.com/en-us/library/ms733025.aspx

    我建议将客户端和服务器端跟踪加载到服务跟踪查看器工具中,这样您就可以看到相互关联的事件。以下是有关该工具以及如何读取输出的更多信息: http://msdn.microsoft.com/en-us/library/aa751795.aspx

    该工具对于调试此类事情非常宝贵。希望你能马上看到发生了什么。

    如果您仍然无法看到所需的信息,您还可以尝试消息记录(服务跟踪查看器工具也可以读取这些文件)。

    不过,我确实认为您的想法是正确的,因为您认为连接没有正确关闭。尤其是对于异步操作,很容易在没有意识到的情况下做到这一点。过去,当我在最终请求触发之前重新创建我的客户端对象时,这发生在我身上。这导致我关闭了 second 对象的连接,但不是第一个。跟踪查看器很快就向我指出了这一点。

    【讨论】:

    • 我在两端都启用了跟踪,但没有运气。在服务器端,我看到连接来来去去......在某些时候没有更多连接进入。而在客户端,我看到连接工作,直到其中一个抛出 TimeoutException......这就是我得到的全部/跨度>
    • 我会仔细检查您的客户端代理对象的创建然后...确保您没有像我描述的那样加倍。我知道这不是一个非常科学的衡量标准,但你几乎可以肯定你没有关闭所有连接是正确的。
    • 我在中间确实有事件和处理程序,所以它可能是没有被释放的东西
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-07-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多