gpt4 book ai didi

c# - 使用 ClientBase 的 WCF 在首次访问时速度较慢

转载 作者:太空宇宙 更新时间:2023-11-03 15:24:33 26 4
gpt4 key购买 nike

我有一个 WCF 客户端/服务器,客户端代理正在使用 ClientBase<T> 。当访问客户端代理时,对任何服务的第一次调用大约需要 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

以为这就是解决方案,但遗憾的是长期启动仍然存在

编辑2:

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

最佳答案

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

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

关于c# - 使用 ClientBase<T> 的 WCF 在首次访问时速度较慢,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35922730/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com