4

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
    }; 

私の質問は、上記のコードのどこにこれインスタンスに追加する必要があるかということです。throttlingBehaviourMusicRepo_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...これが私を混乱させた理由です。

4

3 に答える 3

18

私のように、実行時に構成する人のために、コードで実行できます。

バージョン:

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

C# バージョン:

    ServiceThrottlingBehavior stb = new ServiceThrottlingBehavior {
        MaxConcurrentSessions = 100,
        MaxConcurrentCalls = 100,
        MaxConcurrentInstances = 100
    };
    ServiceHost.Description.Behaviors.Add(stb);
于 2013-08-14T12:21:58.853 に答える
6

スロットリングは、クライアント側ではなくサービス側(サーバー)の動作です

アーノン

于 2009-05-12T19:44:13.390 に答える
3

構成ファイルで動作を指定することができ、生成されたクライアントは動作を使用して従います。

簡潔にするために一部の構成セクションを除外

<service 
    behaviorConfiguration="throttleThis" />

        <serviceBehaviors>
            <behavior name="throttleThis">
                <serviceMetadata httpGetEnabled="True" />
                <serviceThrottling
                    maxConcurrentCalls="40"
                    maxConcurrentInstances="20"
                    maxConcurrentSessions="20"/>
            </behavior>
        </serviceBehaviors>
于 2009-04-27T17:00:06.327 に答える