WCFサービスのインスタンスを返すための次のコードがありますServiceClient
。
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
、私が使用していないのにaを使用してOpen()
いて、インスタンスを開いているときに(を使用して)開いていることに注意してくださいMusicRepo_DBAccess_ServiceClient
...これが私を混乱させた理由です。