Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

wcf channelfactory and opentimeout

Tags:

wcf

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

like image 591
Alexandre Avatar asked Jan 21 '12 12:01

Alexandre


1 Answers

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;
    }
like image 137
Mimas Avatar answered Nov 02 '22 08:11

Mimas