【问题标题】:WCF timing out intermittentlyWCF 间歇性超时
【发布时间】:2009-09-08 23:17:43
【问题描述】:

全部,

我有一个 WCF 服务间歇性超时,通常是在来自 asp.net 客户端的大约十到十二个请求之后。该服务使用反射在其程序集 (WAP dll) 中查找具有自定义属性集的类。这个过程本身非常快,通常只需要几毫秒,当它工作时,效果很好。

在调用代码和服务本身中设置断点告诉我在从 WCF 客户端代理类调用和实际执行该方法之间发生超时。

想法?

更新:来自 web.config 的绑定等:

<system.serviceModel>
    <behaviors>
      <serviceBehaviors>
        <behavior name="Sdd.Services.ControlPanelBehavior">
          <serviceMetadata httpGetEnabled="true" />
          <serviceDebug includeExceptionDetailInFaults="false" />
        </behavior>
      </serviceBehaviors>
    </behaviors>
    <services>
      <service behaviorConfiguration="Sdd.Services.ControlPanelBehavior"
        name="Sdd.Services.ControlPanel">
        <endpoint address="" binding="wsHttpBinding" contract="Sdd.Services.IControlPanel">
          <identity>
            <dns value="localhost" />
          </identity>
        </endpoint>
        <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
      </service>
    </services>
  </system.serviceModel>

更新:这是客户端 web.config 中的相关部分:

 <system.serviceModel>
  <bindings>
   <wsHttpBinding>
    <binding name="WSHttpBinding_IControlPanel" closeTimeout="00:01:00"
     openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
     bypassProxyOnLocal="false" transactionFlow="false" hostNameComparisonMode="StrongWildcard"
     maxBufferPoolSize="524288" maxReceivedMessageSize="65536" messageEncoding="Text"
     textEncoding="utf-8" useDefaultWebProxy="true" allowCookies="false">
     <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
      maxBytesPerRead="4096" maxNameTableCharCount="16384" />
     <reliableSession ordered="true" inactivityTimeout="00:10:00"
      enabled="false" />
     <security mode="Message">
      <transport clientCredentialType="Windows" proxyCredentialType="None"
       realm="" />
      <message clientCredentialType="Windows" negotiateServiceCredential="true"
       algorithmSuite="Default" establishSecurityContext="true" />
     </security>
    </binding>
   </wsHttpBinding>
  </bindings>
  <client>
   <endpoint address="http://localhost:81/services/ControlPanel.svc"
    binding="wsHttpBinding" bindingConfiguration="WSHttpBinding_IControlPanel"
    contract="PublicSite.IControlPanel" name="WSHttpBinding_IControlPanel">
    <identity>
     <dns value="localhost" />
    </identity>
   </endpoint>
  </client>
 </system.serviceModel>

【问题讨论】:

  • 您有更多信息吗?您使用的是什么类型的配置(绑定、客户端和服务器的位置、不同的超时设置是什么)。当您增加超时时会发生什么?
  • 客户端和服务器都在我的开发盒上,在 UltiDev Cassini 下运行。当它工作时,响应时间低于 50 毫秒。这是一致的,直到它突然不起作用,几分钟后超时。我不确定绑定是什么——我在 VS2008 中采用了右键单击、添加... WCF 服务的幼稚方法。如果您能指出我在哪里可以找到该信息,我将很乐意向您报告。谢谢!
  • 我知道它正在攻击症状,但请检查您的绑定超时设置。有关说明,请参阅msdn.microsoft.com/en-us/library/ms731291.aspx
  • 如果不清楚:客户端和服务器是同一服务器上的两个单独的 Web 应用程序项目。
  • David,绑定信息应该已经写入服务的 app.config 文件了。

标签: asp.net wcf


【解决方案1】:

哎呀!

这可能是最愚蠢的错误,但我发现了问题:因为我习惯使用 Web 引用(.asmx Web 服务)而不是服务引用(WCF),我忽略了关闭代理对象。改变了

 [WebMethod]
    public static List<Page>PagesGetAll()
    {
        ControlPanelClient cp = new ControlPanelClient();
        Page[] pageArray = cp.NavigationPagesGetAll();
        List<Page> pageList = pageArray.ToList<Page>();

        // make sure that the page list in the database is up-to-date.
        foreach(Page page in pageList)
            Navigation.PageUpdate(page);

        return pageList;
    }

    public static List<Page>PagesGetAll()
    {
        List<Page> pageList = null;

        using (ControlPanelClient cp = new ControlPanelClient())
        {
            Page[] pageArray = cp.NavigationPagesGetAll();
            pageList = pageArray.ToList<Page>();
            // implied cp.Close() from "using" statement
        }

        // make sure that the page list in the database is up-to-date.
        foreach(Page page in pageList)
            Navigation.PageUpdate(page);

        return pageList;
    }

然后问题就消失了。在验证了这个解决方案之后,我还增加了并发请求的数量,因为有超过 10-12 个并发请求会产生与我之前看到的相同的问题,这似乎是合乎逻辑的。

谢谢大家!

【讨论】:

  • 大声笑,在我看到答案(错误的答案排序顺序)之前,我在上面关于代理中止/关闭的问题中添加了评论:D
【解决方案2】:

帮助诊断此类问题的一个好方法是启用对client and the server 的跟踪并使用Service Trace View Tool。这将使您更好地了解问题的确切位置(在什么方法或调用中)。

【讨论】:

    【解决方案3】:

    不幸的是,最重要的配置部分(绑定和服务端点)丢失了 - 客户端配置也是如此。

    但是按照您的描述,10-12 个请求似乎工作正常,然后出现故障,这可能表明服务器上存在并发/限制问题。

    我会尝试增加并发呼叫和会话的数量,看看是否有帮助。为此,您需要在服务器上的行为配置中添加 serviceThrottling 部分:

    <behavior name="Sdd.Services.ControlPanelBehavior">
       <serviceMetadata httpGetEnabled="true" />
       <serviceDebug includeExceptionDetailInFaults="false" />
       <serviceThrottling
          maxConcurrentCalls="25"          // default is 16
          maxConcurrentSessions="25"       // default is 10
          maxConcurrentInstances="25" />   // no default
    </behavior>
    

    如果这有帮助 - 您遇到了太多会话或同时打开的呼叫的问题。 wsHttpBinding 协议默认会使用会话,所以也许你只需要告诉它使用 per-call 来代替。

    马克

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-10-05
      • 2012-10-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多