In a client, I'm trying to connect to a WCF changing OpenTimeout
property to 5 seconds but it's not working.... here is how I'm creating the channel:
NetTcpBinding bind = new NetTcpBinding(SecurityMode.None);
bind.OpenTimeout = new TimeSpan(0, 0, 5);
var channel = new ChannelFactory<IService>(bind, new EndpointAddress(myAddr));
channel.CreateChannel();
After this, I'm calling the method but if the server is out, it takes 21 seconds and not the 5 that I changed on OpenTimeout
, Am I missing something?
Tks
I resolved this problem in the next way. It seem to be works.
protected TServiceContract CreateChannel()
{
TServiceContract channel = factory.CreateChannel();
var ar = ((IChannel)channel).BeginOpen( null, null );
if( !ar.AsyncWaitHandle.WaitOne( factory.Endpoint.Binding.OpenTimeout, true ) )
{
throw new TimeoutException( "Service is not available" );
}
((IChannel)channel).EndOpen( ar );
return channel;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With