How to avoid wcf service call hang issue if service is not available?

One07k-4914 101 Reputation points
2021-05-12T15:03:48.287+00:00

Hello,

I have to implement wcf client reconnection.

Here requirement 1:Service is not up

        var inst = new InstanceContext(new TestCallBack(this));
        var b = new NetTcpBinding();
        b.SendTimeout = new TimeSpan(1, 59, 59);
        b.ReceiveTimeout = new TimeSpan(1, 59, 59);
        b.Security.Mode = SecurityMode.None;
        b.MaxBufferPoolSize = int.MaxValue;
        b.MaxBufferSize = int.MaxValue;
        b.MaxReceivedMessageSize = int.MaxValue;
        b.ReliableSession.Enabled = true;
        b.ReliableSession.InactivityTimeout = new TimeSpan(1, 59, 59);



      var  Channel = new DuplexChannelFactory<ITest>(inst, b);
        var epAddress = new EndpointAddress("net.tcp://localhost:8485/Service/Test");
       Itest test  = Channel.CreateChannel(epAddress);
        **test?.Initialize();**//Hangs here


 When service is not available i am trying to create the channel.Then i am trying to call Initialize method.It hangs there.Its not returning any failure or anything.
 Is there anyway to make this failure with no connection error or how can i check before calling the method is the channel is opened and ready for the communcation.
 Please help me to solve this.Attached the code snippet.
Developer technologies | .NET | Other
{count} votes

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.