WCF Max Instances似乎限制为10

Rob*_*man 13 wcf iis-7.5

我有一个在IIS7.5中托管的简单WCF服务,使用消息安全性和InstanceContextMode.PerCall通过wsHttp绑定公开

我有一个简单的UI,可以旋转可配置数量的线程,每个线程都调用该服务.

我添加了perfmon计数器ServiceModel4.Instances.无论创建的线程数和调用服务的数量如何,perfmon都会显示该服务最多可创建10个实例.

我的客户端配置如下:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>

  <bindings>
    <wsHttpBinding>

      <binding name="WSHttpBinding_IService3">
        <security mode="Message">
          <transport clientCredentialType="Windows" proxyCredentialType="None"
            realm="" />
          <message clientCredentialType="Windows" negotiateServiceCredential="true"
            algorithmSuite="Default" establishSecurityContext="false" />
        </security>
      </binding>

    </wsHttpBinding>
  </bindings>
  <client>

    <endpoint address="http://localhost/NGCInstancing/Service3.svc/~/Service3.svc"
      binding="wsHttpBinding" bindingConfiguration="WSHttpBinding_IService3"
      contract="NGCSecPerCall.IService3" name="WSHttpBinding_IService3">
      <identity>
        <servicePrincipalName value="host/RB-T510" />
      </identity>
    </endpoint>

  </client>
</system.serviceModel>
</configuration>
Run Code Online (Sandbox Code Playgroud)

我的服务配置如下:

<?xml version="1.0"?>
<system.serviceModel>
    <configuration>
        <behaviors>
            <serviceBehaviors>
                <behavior name="SecPerCallBehaviour">
                    <serviceThrottling maxConcurrentCalls="30" maxConcurrentSessions="1000"
                    maxConcurrentInstances="30" />
                    <serviceMetadata httpGetEnabled="true" />
                    <serviceDebug includeExceptionDetailInFaults="false" />
                </behavior>
                <behavior name="">
                    <serviceMetadata httpGetEnabled="true" />
                    <serviceDebug includeExceptionDetailInFaults="false" />
                </behavior>
            </serviceBehaviors>
        </behaviors>
    <bindings>
        <wsHttpBinding>
            <binding name="BindingMessageSecPerCall" >
            <security mode="Message">
            <!-- it's by setting establishSecurityContext to false that we enable per call instancing with security -->
            <message establishSecurityContext="false" />
            </security>
            </binding>
        </wsHttpBinding>
    </bindings>
    <services>
        <service name="ServiceInstancingDemo.Service3" behaviorConfiguration="SecPerCallBehaviour">
        <endpoint address="~/Service3.svc"
        binding="wsHttpBinding" bindingConfiguration="BindingMessageSecPerCall"
        contract="ServiceInstancingDemo.IService3" />
        </service>
    </services>
    </configuration>
</system.serviceModel>
Run Code Online (Sandbox Code Playgroud)

客户端代码如下:

private void btnSecPerCall_Click(object sender, EventArgs e)
    {
        int i;
        int requests;
        int delay;

        lblStatus.Text = "";

        DateTime startTime = DateTime.Now;
        this.listBox1.Items.Add("start time=" + DateTime.Now);

        delay = Convert.ToInt16(txtDelay.Text);
        requests = Convert.ToInt16(txtRequests.Text);

        Task<string>[] result;
        result = new Task<string>[requests];

        for (i = 0; i < requests; i++)
        {
            result[i] = Task<string>.Factory.StartNew(() => _ngcSecPerCall.WaitThenReturnString(delay));
        }

        for (i = 0; i < requests; i++)
        {
            this.listBox1.Items.Add(result[i].Result);
        }

        DateTime endTime = DateTime.Now;
        TimeSpan ts = endTime - startTime;
        lblStatus.Text = "Finished! Time taken= " + ts.Seconds + " seconds";

        this.listBox1.Items.Add("end time=" + DateTime.Now);
    }
Run Code Online (Sandbox Code Playgroud)

我的服务代码如下:

[ServiceBehavior(InstanceContextMode = InstanceContextMode.PerCall)]
public class Service3 : IService3
{
    private int m_counter;

    public string WaitThenReturnString(int waitMilliSeconds)
    {
        System.Threading.Thread.Sleep(waitMilliSeconds);
        int maxT, workCT;
        System.Threading.ThreadPool.GetMaxThreads(out maxT, out workCT);
        m_counter++;
        return String.Format("Incrementing counter to {0}.\r\nSession Id: {1}. Threads {2}, {3}", m_counter, OperationContext.Current.SessionId, maxT, workCT);
    }
}
Run Code Online (Sandbox Code Playgroud)

该服务返回400,400的线程数.

有谁知道为什么服务拒绝创建更多的10个实例?

如果我创建了服务的副本但是使用了wsHttp绑定,<security mode="None"/>那么服务就会愉快地创建更多实例.

Gra*_*ter 20

您是在Windows Server或Windows 7上进行测试吗?我问的原因是客户端操作系统版本上的IIS有10个连接限制.这是为了防止客户端OS在服务器环境中使用.