gpt4 book ai didi

WCF 最大实例数似乎限制为 10

转载 作者:行者123 更新时间:2023-12-02 01:29:37 27 4
gpt4 key购买 nike

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

我有一个简单的 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);
}
}

服务返回线程数 400,400。

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

如果我创建服务的副本,但使用具有 <security mode="None"/> 的 wsHttp 绑定(bind)然后该服务愉快地创建了更多实例。

最佳答案

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

关于WCF 最大实例数似乎限制为 10,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7822477/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com