question

la07k-4914 avatar image
0 Votes"
la07k-4914 asked PengDing-MSFT commented

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

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.


windows-wcf
· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Hi @la07k-4914 , After my test, I found that if the WCF service is not started, I will get System.ServiceModel.EndpointNotFoundException if I create a channel factory and call the WCF service.

0 Votes 0 ·

0 Answers