我有一段这样的代码
NetTcpBinding binding = new NetTcpBinding(SecurityMode.Transport);
binding.Security.Message.ClientCredentialType = MessageCredentialType.Windows;
binding.CloseTimeout = new TimeSpan(0, 0, 1);
binding.OpenTimeout = new TimeSpan(0, 0, 1);
binding.SendTimeout = new TimeSpan(0, 0, 1);
binding.ReceiveTimeout = new TimeSpan(0, 0, 1);
EndpointAddress endPoint = new EndpointAddress(new Uri(clientPath));
DuplexChannelFactory<Iservice> channel = new DuplexChannelFactory<Iservice>(new ClientCallBack(clientName), binding, endPoint);
channel.Ping()
当端点不存在时,它仍会等待 20 秒,然后抛出 EndpointNotFoundException。
奇怪的是,当我更改 SendTimeout 时,异常消息从 连接尝试持续了 00:00:20 到 ..01 的时间跨度,但仍然需要 20 秒才能抛出异常!
我如何更改此超时?
最佳答案
我认为这与 WCF 无关,因为每当您尝试连接到任何不存在的端点时,操作系统的 TCP/IP 层肯定会通过一些步骤首先找出 DNS 是否基于其名称的主机,并且然后尝试连接到 IP 端点,在此 TCP/IP 层将默认超时 20 秒,即使您在 IE 的地址栏上键入任何不存在的 url,如果它连接到互联网,它也会等待几秒钟之前给你页面无法显示的错误。我认为这就是无法从 WCF 控制的 TCP/IP 堆栈超时。
关于c# - WCF:使用什么超时属性?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1464223/