【问题标题】:WCF using ClientBase<T> slow on first accessWCF 使用 ClientBase<T> 首次访问速度慢
【发布时间】:2016-03-10 17:01:01
【问题描述】:

我有一个 WCF 客户端/服务器,客户端代理正在使用 ClientBase&lt;T&gt;。访问客户端代理时,对任何服务的第一次调用大约需要 8 秒。随后的调用(在 15 秒超时内)大约需要 0.5 秒。我找到了以下文章:

http://blogs.msdn.com/b/wenlong/archive/2010/02/11/why-does-wcf-become-slow-after-being-idle-for-15-seconds.aspx

首先有一条评论建议这已在 .net 4.5 中修复(我使用的是 4.5.1,但我仍然面临这个问题)。我已尝试实施建议的解决方法,但仍然存在此问题。

我的客户端代理代码:

public class MyClient : ClientBase<IMyBrowser>, IMyBrowser
{
    private MyClient(Binding binding, EndpointAddress remoteAddress) : base(binding, remoteAddress) { }

    public string GetCustomerCommissionGroup(string customerId)
    {
        string _result = null;
        try
        {
            _result = Channel.GetCustomerCommissionGroup(customerId);
        }
        catch (FaultException<MyFault> _fault)
        {
          // do something
        }
        return _result;
    }
}

客户端配置:

<system.serviceModel>

<bindings>
  <netTcpBinding>
    <binding name="netTcpNone">
      <security mode="None"/>
    </binding>
  </netTcpBinding>
</bindings>

<services>

  <service name="MyService" behaviorConfiguration="StandardBehaviour">
    <endpoint address="" binding="netTcpBinding" bindingConfiguration="netTcpNone" contract="MyBrowser">
      <identity>
        <dns value="localhost"/>
      </identity>
    </endpoint>
    <host>
      <baseAddresses>
        <add baseAddress="net.tcp://localhost:23456/MyService.svc"/>
      </baseAddresses>
    </host>
  </service>

</services>

<behaviors>
  <serviceBehaviors>
    <behavior name="StandardBehaviour">
      <serviceDebug includeExceptionDetailInFaults="true"/>
      <serviceMetadata httpGetEnabled="false"/>
    </behavior>
  </serviceBehaviors>
</behaviors>

</system.serviceModel>

我在 Windows 服务应用程序中托管它,使用 Net.Tcp 并且没有适当的安全性。

编辑:

http://blogs.msdn.com/b/wenlong/archive/2007/10/26/best-practice-always-open-wcf-client-proxy-explicitly-when-it-is-shared.aspx

认为这是解决方案,但遗憾的是,漫长的启动仍然存在

EDIT2:

我决定修改我的解决方案以在 WCF 上使用 WebAPI。我目前在启动时仍有延迟(约 2 秒),但与 WCF 相比,我的日志记录更好,控制更简单。

【问题讨论】:

    标签: c# wcf


    【解决方案1】:

    我发现一篇文章提到 NetBios 是一个潜在的原因。我在我的托管服务器上禁用了此服务以及 WINS 和 LMHosts 查找,超时从约 8 秒减少到约 3.5 秒。赢了!

    http://www.codeproject.com/Tips/114132/WCF-First-Call-Slow

    【讨论】:

      猜你喜欢
      • 2012-02-06
      • 1970-01-01
      • 2012-10-03
      • 2012-09-25
      • 1970-01-01
      • 2011-11-12
      • 1970-01-01
      • 1970-01-01
      • 2020-10-12
      相关资源
      最近更新 更多