WCF: Comment append un ServiceThrottlingBehavior à un service WCF?

J’ai le code ci-dessous pour renvoyer une instance de mon service ServiceClient WCF:

  var readerQuotas = new XmlDictionaryReaderQuotas() { MaxDepth = 6000000, MaxSsortingngContentLength = 6000000, MaxArrayLength = 6000000, MaxBytesPerRead = 6000000, MaxNameTableCharCount = 6000000 }; var throttlingBehaviour = new ServiceThrottlingBehavior(){MaxConcurrentCalls=500,MaxConcurrentInstances=500,MaxConcurrentSessions = 500}; binding = new WSHttpBinding(SecurityMode.None) {MaxReceivedMessageSize = 6000000, ReaderQuotas = readerQuotas}; dualBinding = new WSDualHttpBinding(WSDualHttpSecurityMode.None) {MaxReceivedMessageSize = 6000000, ReaderQuotas = readerQuotas}; endpointAddress = new EndpointAddress("http://localhost:28666/DBInteractionGateway.svc"); return new MusicRepo_DBAccess_ServiceClient(new InstanceContext(instanceContext), dualBinding, endpointAddress); 

Dernièrement, j’avais des problèmes avec les délais d’attente et j’ai donc décidé d’append un comportement de limitation, comme celui-ci:

  var throttlingBehaviour = new ServiceThrottlingBehavior () { MaxConcurrentCalls=500, MaxConcurrentInstances=500, MaxConcurrentSessions = 500 }; 

Ma question est la suivante: dans le code ci-dessus, dois-je append ce throttlingBehaviour à mon instance MusicRepo_DBAccess_ServiceClient ?


Parmi les exemples que j’ai trouvés sur le Web, ils font quelque chose comme ceci:

 ServiceHost host = new ServiceHost(typeof(MyService)); ServiceThrottlingBehavior throttleBehavior = new ServiceThrottlingBehavior { MaxConcurrentCalls = 40, MaxConcurrentInstances = 20, MaxConcurrentSessions = 20, }; host.Description.Behaviors.Add(throttleBehavior); host.Open(); 

Notez que dans le code ci-dessus, ils utilisent un ServiceHost alors que je ne le suis pas. Ils l’ouvrent ensuite (avec Open() ) alors que j’ouvre l’instance MusicRepo_DBAccess_ServiceClient … et c’est ce qui m’a dérouté.

Vous pouvez spécifier le comportement dans le fichier de configuration autant que possible, et le client généré obéira en utilisant des comportements.

Certaines sections de configuration sont exclues pour des raisons de brièveté

        

Peut être fait en code pour ceux, comme moi, qui configurent à l’exécution.

version vb:

  Dim stb As New ServiceThrottlingBehavior stb.MaxConcurrentSessions = 100 stb.MaxConcurrentCalls = 100 stb.MaxConcurrentInstances = 100 ServiceHost.Description.Behaviors.Add(stb) 

version c #:

  ServiceThrottlingBehavior stb = new ServiceThrottlingBehavior { MaxConcurrentSessions = 100, MaxConcurrentCalls = 100, MaxConcurrentInstances = 100 }; ServiceHost.Description.Behaviors.Add(stb); 

La limitation est un comportement côté serveur (serveur) et non pas côté client

Arnon