我已经为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秒。
然而,当实际调用open时,我看到了一个21秒的超时。
调试2013-07-31 18:12:44,712 Communication.WcfCommunicator - NotifyAllReceivers: Type: AskWhoIsAwake,SentDate: 7/31/2013 18:12:44 AM,DetectSessionId: 376 9eb7 b563-458 b-9 eb7-a90e81f82563-1 调试2013-07-31 18:13:05,746 Communication.WcfCommunicator -无法连接到net.tcp://notup/xxx.svc/motup_www-xxx com。连接尝试持续时间为00:00:00.9879988。TCP错误代码10060:连接尝试失败是因为连接方在一段时间后没有正确响应,或建立连接失败是因为连接主机未能响应42.42.42:808。-6
是什么导致了额外的20秒超时?
发布于 2013-08-01 03:59:34
使用异步打开和设置超时解决问题。
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);https://stackoverflow.com/questions/17969187
复制相似问题