WCF Max实例似乎限制为10个

WCF Max实例似乎限制为10个,wcf,iis-7.5,Wcf,Iis 7.5,我有一个简单的WCF服务,托管在IIS7.5中,通过使用消息安全性和InstanceContextMode.PerCall的wsHttp绑定公开 我有一个简单的UI,它可以启动可配置数量的线程,每个线程调用服务 我已经添加了perfmon计数器ServiceModel4.Instances。无论创建和调用服务的线程数量如何,perfmon显示该服务最多创建10个实例 我的客户端配置如下: <?xml version="1.0" encoding="utf-8" ?> <conf

我有一个简单的WCF服务,托管在IIS7.5中,通过使用消息安全性和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>
<?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>
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);
    }
[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);
    }
}
服务返回400400的线程数

有人知道为什么服务拒绝创建超过10个实例吗

如果我创建了该服务的一个副本,但带有一个具有
的wsHttp绑定,那么该服务很高兴地创建了更多的实例。

提到了对来自同一AppDomain的客户端请求的优化。您的示例代码基本上与服务上的套接字相同。由于每个客户端都有一些限制,这可能会影响您的服务行为。此外,10恰好是MaxConcurrentSessions的默认值,因此您的配置可能没有更改WCF默认值


启用安全性会影响整个线程,因为它会为每个客户端建立一个“会话”,这样发送的每个请求就不需要在每次调用时进行身份验证。这些安全“会话”计入MaxConcurrentSessions总数。

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

您是否在同一台计算机上运行客户端和服务器?然后他们可能会争夺可用的线程

如果您在不同的PC上运行,请确保在客户端和服务器上都进行了以下配置更改

客户端向同一服务器生成的请求可能不超过10个。因此,请首先在客户端和服务器上尝试上述配置


当然,你必须有一个Windows服务器。否则,这将是Windows 7上的IIS限制。

值得我补充的是,我已经使用不同的绑定实现了相同的服务。新的绑定也是wsHttp,但具有。当我针对这个服务运行同一个客户机时,该服务很高兴地增加了10多个实例。我猜对于新绑定,会话没有被使用,因为不需要建立安全上下文。我想您已经了解到10是默认的MaxConcurrentSessions,但我的配置会尝试将该值更改为1000。有人知道如何检查运行时使用的实际设置吗?我将测试转移到Win2008虚拟机上,现在效果很好-我得到了61个实例,而不是Win7主机上的10个。非常感谢赛斯!这听起来很有希望!我正在使用Windows7。我明天将部署到win2008虚拟机,然后回来。是的,就是这样。当我在Win2008虚拟机上测试时,它工作得很好。非常感谢,谢谢