none
WCF detect network fauilre and change OperationTimeout on the fly RRS feed

  • Question

  • i wrote a WCF service in my application the problem i facing , is : if a client sent a request to the server , and there was a network failure(for any reason) (as you see in the code below my Operation Time out has to be 24 hours), the operation wait's 24 hours even if i plug the network cable back , my goal is to change the operation time out after network disconnect detected, but i faild to so with set new time out.
     
    if there a way to do this in WCF from the client side, so that i can catch time out exception?
     
    binding config : 

     public static NetTcpBinding GetCustomNetTcpBinding()
        {
            int maxSize = 10000000;
            NetTcpBinding netTcpBind = new NetTcpBinding();
            netTcpBind.MaxReceivedMessageSize = maxSize;
            netTcpBind.MaxBufferSize = maxSize;
            netTcpBind.ReaderQuotas.MaxBytesPerRead = maxSize;
            netTcpBind.ReaderQuotas.MaxArrayLength = maxSize;
            netTcpBind.ReceiveTimeout = TimeSpan.MaxValue;
            netTcpBind.CloseTimeout = TimeSpan.MaxValue;
            netTcpBind.SendTimeout = TimeSpan.MaxValue;
            netTcpBind.ReliableSession.Enabled = true;
            netTcpBind.ReliableSession.InactivityTimeout = TimeSpan.MaxValue;
            return (netTcpBind);
        }

    i detecting network failure with ping class on different thread :

     try
                {                    
                    Ping PingRequest = new Ping();
                    PingReply ResualtPing = PingRequest.Send(m_hostIP);
                    if (ResualtPing.Status != IPStatus.Success)
                    {
                            IContextChannel icc;
                    icc = (IContextChannel)_Service;                    
                icc.OperationTimeout = new TimeSpan(0, 0, 30)
                    }
                    else
                    {
     
                    }
                }
                catch (Exception ex)
                {
                    IContextChannel icc;
                    icc = (IContextChannel)_Service;                    
                icc.OperationTimeout = new TimeSpan(0, 0, 30);
     
                }

    and then create :

      try
        {            
            IContextChannel icc;
                    _scf = new ChannelFactory<IService>(ServiceUtils.GetCustomNetTcpBinding(), "net.tcp://" + _hostIP + ":" + _TCPPort.ToString());
     
                    _Service = _scf.CreateChannel();
                    icc = (IContextChannel)_Service;
                    icc.OperationTimeout = new TimeSpan(0, 0, 30);
     
                    _Service.Create(/*params*/);
                }
     
                catch (Exception e)
                {
                    /*some code */
                }
     
                icc.OperationTimeout = new TimeSpan(24, 0, 0);//(here i have to set the         operaionTimeOut for 24 hours)



    Wednesday, December 10, 2014 11:09 AM

Answers