WCF间歇性超时 [英] WCF timing out intermittently

查看:92
本文介绍了WCF间歇性超时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

全部

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

I have a WCF service that times out intermittently, usually after about ten or twelve requests from the asp.net client. The service uses reflection to find classes in its assembly (WAP dll) that have a custom attribute set. The process itself is very quick, usually taking only a few milliseconds, and when it works, it works great.

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

Setting a breakpoint in the calling code and in the service itself tells me that the timeout is occurring between the call from the WCF client proxy class and when that method is actually executed.

想法?

更新:从web.config中绑定等:

Update: binding, etc from 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中的相关部分:

UPDATE: And here's the relevant portion from the client's 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>

推荐答案

糟糕!

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

This is probably the most idiotic of mistakes, but I figured out the problem: since I'm used to using web references (.asmx web service) instead of service references (WCF), I neglected to close the proxy object. Changed

 [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个以上的并发请求会造成我以前遇到的相同问题.

And the problem disappeared. After verifying this solution I also increased the number of concurrent requests as it seems logical that having more than 10-12 concurrent requests would create the same problem I was seeing before.

谢谢大家!

这篇关于WCF间歇性超时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆