WCF обрывается канал через 9 часов работы
От: anj78  
Дата: 23.04.08 11:14
Оценка:
Есть Сервер и Клиент. Клиент подключается к Серверу по дуплексному каналу через WCF.
После подключения нормально работает без малейших проблем.
Клиент каждые 2 минуты вызывает у сервера функцию CheckConnection для того, чтобы держать канал постоянно открытым.

Проблема состоит в том что через 9 часов нормальной работы на клиенте возникает исключение (см. ниже) а на с сервере канал переходит в Faulted state. После этого клиент переподключается (внутренняя логика работы клиента) и продолжает работать следующие 9 часов без проблем.

Подскажите в чем может быть причина. Мои догадки это время жизни сессии, если я прав, где установить это время?

Ошибка на клиенте:

Message: The server did not provide a meaningful reply; this might be caused by a contract mismatch, a premature session shutdown or an internal server error.
StackTrace:
Server stack trace: 
   at System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean oneway, ProxyOperationRuntime operation, Object[] ins, Object[] outs, TimeSpan timeout)
   at System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean oneway, ProxyOperationRuntime operation, Object[] ins, Object[] outs)
   at System.ServiceModel.Channels.ServiceChannelProxy.InvokeService(IMethodCallMessage methodCall, ProxyOperationRuntime operation)
   at System.ServiceModel.Channels.ServiceChannelProxy.Invoke(IMessage message)

Exception rethrown at [0]: 
   at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg)
   at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type)
   at PT.DTL.IPTService.CheckConnection()
   at PT_BLL.Biz_objects.BizServerOperation.CheckConnection()



Настройки канала на клиенте :

        public static void CreateChannel()
        {
            try
            {
                callbackClass = new PosForLSCallback();
                instanceContext = new InstanceContext(callbackClass);
                Uri uri = new Uri(_uri);
                NetTcpBinding binding = new NetTcpBinding();
                binding.Security.Mode = SecurityMode.Message;
                binding.ReliableSession.InactivityTimeout = TimeSpan.MaxValue;
                binding.ReliableSession.Ordered = true;
                binding.ListenBacklog = 1000;
                binding.MaxConnections = 1000;
                binding.MaxReceivedMessageSize = 294967296;
                binding.MaxBufferSize = 294967296;
                binding.ReaderQuotas.MaxArrayLength = 294967296;
                binding.ReaderQuotas.MaxBytesPerRead = 294967296;
                binding.ReaderQuotas.MaxStringContentLength = 294967296;
                binding.OpenTimeout = TimeSpan.FromSeconds(30);
                binding.Security.Message.AlgorithmSuite
                     = System.ServiceModel.Security.SecurityAlgorithmSuite.Basic128Rsa15;

                binding.Security.Message.ClientCredentialType = MessageCredentialType.None;

                EndpointAddress ad = new EndpointAddress(
                    uri,
                    new DnsEndpointIdentity(BasicObject.CERTIFICATE_CAFE),
                    new AddressHeaderCollection());

                factoryLS = new DuplexChannelFactory<IPOSService>(instanceContext, binding, ad);
                factoryLS.Credentials.ServiceCertificate.Authentication.CertificateValidationMode
                    = System.ServiceModel.Security.X509CertificateValidationMode.PeerOrChainTrust;
                factoryLS.Credentials.ServiceCertificate.Authentication.TrustedStoreLocation = StoreLocation.LocalMachine;
                factoryLS.Open();
                channel = factoryLS.CreateChannel();
            }
            catch (Exception ex)
            {
                VS2Exception.WriteError("CreateChannel", ex);
                Console.WriteLine(ex.Message);
            }
        }


Настройки канала на сервере:

        private static void createPOSHost()
        {
            try
            {
                NetTcpBinding binding = binding = new NetTcpBinding(SecurityMode.Message);

                binding.MaxReceivedMessageSize = 294967296;
                binding.MaxBufferSize = 294967296;
                binding.ReaderQuotas.MaxArrayLength = 294967296;
                binding.ReaderQuotas.MaxBytesPerRead = 294967296;
                binding.ReaderQuotas.MaxStringContentLength = 294967296;
                binding.OpenTimeout = TimeSpan.FromSeconds(30);
                binding.ReliableSession.Ordered = true;
                binding.ListenBacklog = 1000;
                binding.MaxConnections = 1010;
                binding.ReceiveTimeout = TimeSpan.FromSeconds(VS2Settings.Instance().TerminalQueryInterval + TimeoutIncrease);
                binding.Security.Message.AlgorithmSuite
                 = System.ServiceModel.Security.SecurityAlgorithmSuite.Basic128Rsa15;
                binding.Security.Message.ClientCredentialType = MessageCredentialType.None;

                _posHost = new ServiceHost(typeof(POSService));
                _posHost.AddServiceEndpoint(
                    typeof(POS.DTL.IPOSService),
                    binding,
                    string.Format(BasicObjects.ConfigUtil.GetValue(LSARegistryKeys.POSService),
                        BasicObject.LSForPOSPort).Replace("[LS_IP]", LSIP));

                _posHost.Credentials.ServiceCertificate.Certificate = new X509Certificate2(Certs.VS2CAFE, "",         X509KeyStorageFlags.PersistKeySet);

                ServiceThrottlingBehavior stb = new ServiceThrottlingBehavior();
                stb.MaxConcurrentCalls = 1010;
                stb.MaxConcurrentInstances = 1010;
                stb.MaxConcurrentSessions = 1010;
                _posHost.Description.Behaviors.Add(stb);
                _posHost.Faulted += new EventHandler(_posHost_Faulted);
                _posHost.Open();

            }
            catch (Exception ex)
            {
                _log.Error(ex);
            }
        }
 
Подождите ...
Wait...
Пока на собственное сообщение не было ответов, его можно удалить.