C# 如何在使用ChannelFactory创建WCF代理时设置超时?

C# 如何在使用ChannelFactory创建WCF代理时设置超时?,c#,wcf,C#,Wcf,我正在使用channel factory创建WCF代理,如下所示- BasicHttpBinding binding = new BasicHttpBinding(); binding.SendTimeout = new TimeSpan(0, 20, 0); binding.ReceiveTimeout = new TimeSpan(0, 20, 0); binding.OpenTimeout = new TimeSpan(0, 20, 0); binding.

我正在使用channel factory创建WCF代理,如下所示-

BasicHttpBinding binding = new BasicHttpBinding();
    binding.SendTimeout = new TimeSpan(0, 20, 0);
    binding.ReceiveTimeout = new TimeSpan(0, 20, 0);
    binding.OpenTimeout = new TimeSpan(0, 20, 0);
    binding.CloseTimeout = new TimeSpan(0, 20, 0);
    binding.BypassProxyOnLocal = bypassProxyOnLocal;
    binding.HostNameComparisonMode = (HostNameComparisonMode)Enum.Parse(typeof(HostNameComparisonMode), hostNameComparisonMode, true);
    binding.MaxBufferPoolSize = maxBufferPoolSize;
    binding.MaxReceivedMessageSize = maxReceivedMessageSize;
    binding.MessageEncoding = (WSMessageEncoding)Enum.Parse(typeof(WSMessageEncoding), messageEncoding, true);
    binding.TextEncoding = System.Text.Encoding.UTF8;
    binding.UseDefaultWebProxy = useDefaultWebProxy;
    binding.AllowCookies = allowCookies;
    binding.Security.Transport.Realm = securityTransportRealm;
    binding.Security.Message.AlgorithmSuite = SecurityAlgorithmSuite.Default;
    EndpointAddress endpointAddress = new EndpointAddress(endPoint);
    ChannelFactory<T> channelFactory = new ChannelFactory<T>(binding, endpointAddress);
    return channelFactory.CreateChannel(); 

请建议,如何解决此问题?

必须在导线两侧设置超时。你在WCF服务端有控制权吗?是的,我有控制权。在这种情况下,如何在WCF服务端设置超时?您是通过代码配置服务还是通过XML配置服务?你能展示一下相关的部分吗?
Error. \nThe request channel timed out while waiting for a reply after 00:00:59.9843997. Increase the timeout value passed to the call to Request or increase the SendTimeout value on the Binding. The time allotted to this operation may have been a portion of a longer timeout.\n

Server stack trace: 

   at System.ServiceModel.Channels.ServiceChannel.HandleReply(ProxyOperationRuntime operation, ProxyRpc& rpc)

   at System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean oneway, ProxyOperationRuntime operation, Object[] ins, Object[] outs, TimeSpan timeout)

   at System.ServiceModel.Channels.ServiceChannelProxy.InvokeService(IMethodCallMessage methodCall, ProxyOperationRuntime operation)

   at System.ServiceModel.Channels.ServiceChannelProxy.Invoke(IMessage message)