J'ai le code ci-dessous pour revenir en arrière une instance de mon service WCF ServiceClient
:WCF: comment ajouter un ServiceThrottlingBehavior à un service WCF?
var readerQuotas = new XmlDictionaryReaderQuotas()
{
MaxDepth = 6000000,
MaxStringContentLength = 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 donc j'ai décidé d'ajouter un comportement d'étranglement, comme par exemple:
var throttlingBehaviour = new ServiceThrottlingBehavior() {
MaxConcurrentCalls=500,
MaxConcurrentInstances=500,
MaxConcurrentSessions = 500
};
ma question est, où dans le code ci-dessus dois-je ajouter cette throttlingBehaviour
à mon MusicRepo_DBAccess_ServiceClient
exemple?
De quelques-uns des exemples que je 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 suis pas, et ils l'ouvrent alors (avec Open()
) alors que j'ouvre l'instance MusicRepo_DBAccess_ServiceClient
... et c'est ce qui m'a rendu confus.
Pouvez-vous pas cela dans un fichier de configuration? – rguerreiro
J'ai besoin de partager ce service wcf avec plusieurs projets sans qu'ils aient un fichier app.config ... c'est pourquoi je construis la configuration par programme –
Où hébergez-vous le service? – rguerreiro