我有給我回WCF服務ServiceClient
回實例下面的代碼:WCF:如何將ServiceThrottlingBehavior添加到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);
最近我遇到一些麻煩超時,所以我決定增加一個限制行爲,像這樣的:
var throttlingBehaviour = new ServiceThrottlingBehavior() {
MaxConcurrentCalls=500,
MaxConcurrentInstances=500,
MaxConcurrentSessions = 500
};
我的問題是,在上面的代碼中,我應該添加這個throttlingBehaviour
到我的MusicRepo_DBAccess_ServiceClient
實例?
從一些我在網上找到的例子,他們都在做這樣的事情:
ServiceHost host = new ServiceHost(typeof(MyService));
ServiceThrottlingBehavior throttleBehavior = new ServiceThrottlingBehavior
{
MaxConcurrentCalls = 40,
MaxConcurrentInstances = 20,
MaxConcurrentSessions = 20,
};
host.Description.Behaviors.Add(throttleBehavior);
host.Open();
請注意,在上面的代碼中,他們使用的是ServiceHost
,而我不是,和他們然後打開它(與Open()
),而我打開MusicRepo_DBAccess_ServiceClient
實例......這讓我感到困惑。
你不能在配置文件中有這樣的? – rguerreiro 2009-04-27 16:56:49
我需要與多個項目共享此wcf服務,而不需要他們擁有app.config文件...這就是爲什麼我要以編程方式構建配置 – 2009-04-27 16:58:52