【发布时间】:2016-03-10 17:01:01
【问题描述】:
我有一个 WCF 客户端/服务器,客户端代理正在使用 ClientBase<T>。访问客户端代理时,对任何服务的第一次调用大约需要 8 秒。随后的调用(在 15 秒超时内)大约需要 0.5 秒。我找到了以下文章:
首先有一条评论建议这已在 .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 并且没有适当的安全性。
编辑:
认为这是解决方案,但遗憾的是,漫长的启动仍然存在
EDIT2:
我决定修改我的解决方案以在 WCF 上使用 WebAPI。我目前在启动时仍有延迟(约 2 秒),但与 WCF 相比,我的日志记录更好,控制更简单。
【问题讨论】: