Question

J'ai un service Windows qui abrite un hôte WCF NetTcp. À partir du client, quand je commence à faire des appels au service via tcp, ils passent par bien au début, mais après quelques minutes ils commencent tous à donner l'erreur de délai d'attente WCF redoutée qui n'a vraiment rien à voir avec les délais d'attente:

Cette opération de demande envoyée à net.tcp: // myserver:. 8080 / ListingService n'a pas reçu de réponse dans le délai configuré (0:01:00)

J'ai vu d'autres messages sur ce site que beaucoup de fois cela a à voir avec la taille des messages max, mais je l'ai déjà paramétrés les limites, mais en vain.

Voici mon windows code de service:

public partial class Service : ServiceBase
    {
        internal static ServiceHost myHost = null;

        public Service()
        {
            InitializeComponent();
        }

        protected override void OnStart(string[] args)
        {
            System.Net.ServicePointManager.DefaultConnectionLimit = 10000;
            //create host.
            var path = ConfigurationManager.AppSettings["ServiceHostAddress"].ToString();
            myHost = new ServiceHost(typeof(ListingService));
            //add endpoint.
            myHost.AddServiceEndpoint(typeof(IListingService), GetBinding(), path);
            //add behaviors.
            AddBehaviors();
            //open host.
            myHost.Open();
        }

        private void AddBehaviors()
        {
            //service metadata behavior.
            var smb = new ServiceMetadataBehavior();
            smb.MetadataExporter.PolicyVersion = PolicyVersion.Policy15;
            myHost.Description.Behaviors.Add(smb);
            //service throttling behavior.
            var behavior = new ServiceThrottlingBehavior()
            {
                MaxConcurrentCalls = 10000,
                MaxConcurrentInstances = 10000,
                MaxConcurrentSessions = 10000
            };
            myHost.Description.Behaviors.Add(behavior);
            //service debug behavior.
            var serviceDebugBehavior = myHost.Description.Behaviors.Find<ServiceDebugBehavior>();
            serviceDebugBehavior.IncludeExceptionDetailInFaults = true;
        }

        private Binding GetBinding()
        {
            var queueBinding = new NetTcpBinding(SecurityMode.None);
            queueBinding.MaxConnections = 10000;
            queueBinding.MaxBufferSize = 2048000;
            queueBinding.MaxReceivedMessageSize = 2048000;
            return queueBinding;
        }

        protected override void OnStop()
        {
            if (myHost != null)
            {
                myHost.Close();
                myHost = null; 
            }
        }
    }

Voici la configuration du client dans le cas où il fait une différence:

<system.serviceModel>
    <bindings>

      <netTcpBinding>
        <binding name="NetTcpBinding" transferMode="Buffered" hostNameComparisonMode="StrongWildcard"
          closeTimeout="00:01:00" openTimeout="00:01:00" receiveTimeout="00:01:00" sendTimeout="00:01:00"
          maxBufferSize="2147483647" maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647"><!-- transactionFlow="true"-->
          <security mode="None"/>
          <reliableSession enabled="false"/>
          <readerQuotas maxArrayLength="2147483647"/>
        </binding>
      </netTcpBinding>

    </bindings>
    <client>

      <endpoint
             address="net.tcp://myserver:8080/ListingService"
             binding="netTcpBinding" bindingConfiguration="NetTcpBinding"
             contract="ListingServiceProxy.IListingService" name="NetTcpBinding" />

    </client>
  </system.serviceModel>

Je fais que de fermer les connexions client, voici le code:

public static void Using<T>(this T client, Action<T> work)
            where T : ICommunicationObject
        {
            try
            {
                work(client);
                client.Close();
            }
            catch (CommunicationException)
            {
                client.Abort();
                throw;
            }
            catch (TimeoutException)
            {
                client.Abort();
                throw;
            }
            catch
            {
                client.Abort();
                throw;
            }
        }

new ListingServiceClient().Using(client =>
                {
                    client.SaveListing(listing);
                });
Était-ce utile?

La solution

Ils ont fini parce que la chronogrammes base de données a été fait hors délai, il n'a pas été un problème avec WCF.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top