C# WCF服务节流不工作

C# WCF服务节流不工作,c#,.net,wcf,C#,.net,Wcf,我有一个配置为使用serviceThrottling的WCF服务,但是这似乎不起作用 我有一个多线程客户端调用此服务@ http://localhost:7778/test/sleep?sleep=1000 而服务器似乎忽略了最大值???WCF配置中的设置 我真正想做的是增加并发连接的数量,但似乎我根本没有影响设置 我的服务器托管方式如下: WebServiceHost zHost = new WebServiceHost(typeof (Service1));

我有一个配置为使用serviceThrottling的WCF服务,但是这似乎不起作用

我有一个多线程客户端调用此服务@

http://localhost:7778/test/sleep?sleep=1000 
而服务器似乎忽略了最大值???WCF配置中的设置

我真正想做的是增加并发连接的数量,但似乎我根本没有影响设置

我的服务器托管方式如下:

            WebServiceHost zHost = new WebServiceHost(typeof (Service1));

            zHost.Open();
            Console.WriteLine("Started");
            Console.ReadLine();
            zHost.Close();
    <?xml version="1.0" encoding="utf-8" ?>
    <configuration>
        <startup> 
            <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
        </startup>
      <system.net>
        <connectionManagement>
          <add address="*"  maxconnection="65535"/>
        </connectionManagement>
      </system.net>
      <system.serviceModel>
        <standardEndpoints />
        <behaviors>
          <endpointBehaviors>
            <behavior name="NewBehavior0">
              <webHttp />
            </behavior>
          </endpointBehaviors>
          <serviceBehaviors>
            <behavior name="NewBehavior0">
              <serviceThrottling maxConcurrentCalls="1" maxConcurrentSessions="1" maxConcurrentInstances="1" />
            </behavior> 
          </serviceBehaviors>
        </behaviors>
        <services>
          <service name="WCF_REST_TEST_1.Service1">
            <endpoint address="/test" behaviorConfiguration="NewBehavior0" binding="webHttpBinding" bindingConfiguration="" contract="WCF_REST_TEST_1.IService1" />
            <host>
              <baseAddresses>
                <add baseAddress="http://localhost:7778" />
              </baseAddresses>
            </host>
          </service>
        </services>
      </system.serviceModel>
    </configuration>
[ServiceContract]
public interface IService1
{

    [WebGet(UriTemplate = "sleep?sleep={value}", ResponseFormat = WebMessageFormat.Json)]
    [OperationContract]
    CompositeType sleep(int value);
}
App.config设置如下所示:

            WebServiceHost zHost = new WebServiceHost(typeof (Service1));

            zHost.Open();
            Console.WriteLine("Started");
            Console.ReadLine();
            zHost.Close();
    <?xml version="1.0" encoding="utf-8" ?>
    <configuration>
        <startup> 
            <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
        </startup>
      <system.net>
        <connectionManagement>
          <add address="*"  maxconnection="65535"/>
        </connectionManagement>
      </system.net>
      <system.serviceModel>
        <standardEndpoints />
        <behaviors>
          <endpointBehaviors>
            <behavior name="NewBehavior0">
              <webHttp />
            </behavior>
          </endpointBehaviors>
          <serviceBehaviors>
            <behavior name="NewBehavior0">
              <serviceThrottling maxConcurrentCalls="1" maxConcurrentSessions="1" maxConcurrentInstances="1" />
            </behavior> 
          </serviceBehaviors>
        </behaviors>
        <services>
          <service name="WCF_REST_TEST_1.Service1">
            <endpoint address="/test" behaviorConfiguration="NewBehavior0" binding="webHttpBinding" bindingConfiguration="" contract="WCF_REST_TEST_1.IService1" />
            <host>
              <baseAddresses>
                <add baseAddress="http://localhost:7778" />
              </baseAddresses>
            </host>
          </service>
        </services>
      </system.serviceModel>
    </configuration>
[ServiceContract]
public interface IService1
{

    [WebGet(UriTemplate = "sleep?sleep={value}", ResponseFormat = WebMessageFormat.Json)]
    [OperationContract]
    CompositeType sleep(int value);
}


默认情况下,
InstanceContextMode
PerCall
,因此您必须设置
maxConcurrentCalls
maxConcurrentInstances

看起来您的配置文件是错误的,因为只支持一个调用

<serviceThrottling maxConcurrentCalls="1" maxConcurrentSessions="1" maxConcurrentInstances="1" />

比如说

<system.serviceModel>
    <services>
        <service behaviorConfiguration="ServiceProviderBehavior"
                 name="ServiceProvider">
            <endpoint address="http://localhost:5060/" binding="webHttpBinding"
                      behaviorConfiguration="Web" contract="ServiceContracts.IService" />
        </service>
    </services>
    <behaviors>
        <serviceBehaviors>
            <behavior name="ServiceProviderBehavior">
                <serviceMetadata httpGetEnabled="true" />
                <serviceThrottling maxConcurrentCalls="250" maxConcurrentInstances="250" />
            </behavior>
        </serviceBehaviors>
        <endpointBehaviors>
            <behavior name="Web">
                <webHttp />
            </behavior>
        </endpointBehaviors>
    </behaviors>
</system.serviceModel>


我不确定我是否听懂了。我在帖子中说,即使我的配置设置为maxConcurrentCalls=“1”maxConcurrentSessions=“1”maxConcurrentInstances=“1”。。。它不工作。你的配置似乎和我的完全一样,你只是增加了一些似乎对我的配置没有任何影响的值?