我已经使用这些超时配置了我的wcf:
public static NetTcpBinding MakeTcpBinding(bool isClient)
{
return new NetTcpBinding(SecurityMode.None, false)
{
HostNameComparisonMode = HostNameComparisonMode.StrongWildcard,
TransactionFlow = false,
PortSharingEnabled = true,
Security = {Transport = {ClientCredentialType = TcpClientCredentialType.None}},
ReceiveTimeout = isClient ? TimeSpan.FromSeconds(5) : TimeSpan.FromDays(1),
SendTimeout = isClient ? TimeSpan.FromSeconds(1) : TimeSpan.FromSeconds(5),
OpenTimeout = TimeSpan.FromSeconds(1),
CloseTimeout = TimeSpan.FromSeconds(5),
MaxReceivedMessageSize = int.MaxValue,
ListenBacklog = int.MaxValue,
MaxBufferSize = int.MaxValue,
MaxBufferPoolSize = 524288,
ReaderQuotas =
{
MaxArrayLength = int.MaxValue,
MaxStringContentLength = int.MaxValue,
MaxDepth = int.MaxValue,
MaxBytesPerRead = int.MaxValue,
MaxNameTableCharCount = int.MaxValue
}
};
}
当客户端连接到不存在的服务器时,应该将imeout设置为1秒。
然而,当实际呼叫打开时,我看到21秒超时。
DEBUG 2013-07-31 18:12:44,712 Communication.WcfCommunicator - NotifyAllReceivers:类型:AskWhoIsAwake,SentDate:7/31/2013 18:12:44 AM,DetectSessionId:37106dee-b563-458b-9eb7-a90e81f82563 - 1
DEBUG 2013-07-31 18:13:05,746 Communication.WcfCommunicator - 无法连接到 的net.tcp://notup/xxx.svc/motup_www-xxx-com。连接尝试 持续时间为00:00:00.9879988。 TCP错误代码10060:A 连接尝试失败,因为连接方没有正确 一段时间后回复,或建立连接失败 因为连接的主机无法响应42.42.42.42:808。 - 6
造成额外20秒超时的原因是什么?
答案 0 :(得分:1)
使用异步打开和设置超时解决。
var ar = client.InnerChannel.BeginOpen(null, null);
if (!ar.AsyncWaitHandle.WaitOne(client.Endpoint.Binding.OpenTimeout, true))
throw new CommunicationException("Service is not available");
client.InnerChannel.EndOpen(ar);