【问题标题】:How to apply performance configuration of WCF Service?如何应用 WCF 服务的性能配置?
【发布时间】:2020-09-25 02:46:23
【问题描述】:

我有一个连接的WCF服务,客户端配置代码如下:

var method = typeof(XmlSerializer).GetMethod("set_Mode", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static);
method.Invoke(null, new object[] { 1 });
BasicHttpsBinding httpBd = new BasicHttpsBinding(BasicHttpsSecurityMode.Transport);
httpBd.MaxReceivedMessageSize = Int32.MaxValue;
httpBd.MaxBufferSize = Int32.MaxValue;
var client = new FindServicePortTypeClient(httpBd,
new EndpointAddress(_settings.Url));

var bd = client.Endpoint.Binding as BasicHttpsBinding;
bd.Security.Mode = BasicHttpsSecurityMode.Transport;
bd.Security.Transport.ClientCredentialType = HttpClientCredentialType.Basic;

client.ClientCredentials.UserName.UserName = _settings.User;
client.ClientCredentials.UserName.Password = _settings.Password;

在服务上,我必须配置一些性能指标,例如“关系深度”。我怎样才能做到这一点

【问题讨论】:

    标签: performance wcf configuration metrics throttling


    【解决方案1】:

    在 WCF 中,您可以使用 ServiceThrottlingBehavior 来控制 WCF 服务性能。使用此行为,您可以微调 Windows Communication Foundation 应用程序的性能。

    您可以在配置文件中配置这些属性的值。

        <behaviors>
      <serviceBehaviors>
        <behavior  name="Throttled">
          <serviceThrottling 
            maxConcurrentCalls="1" 
            maxConcurrentSessions="1" 
            maxConcurrentInstances="1"
          />
          <serviceMetadata 
            httpGetEnabled="true" 
            httpGetUrl=""
          />
        </behavior>
      </serviceBehaviors>
    </behaviors>
    

    MaxConcurrentSessions:服务主机接受的最大会话数。默认值为处理器计数的 100 倍。 MaxConcurrentCalls:服务中活动消息的上限。默认值为处理器计数的 16 倍。 MaxConcurrentInstances:一次服务中InstanceContext对象的最大数量。默认是 MaxConcurrentSessions 的值和 MaxConcurrentCalls 的值之和。

    Windows Communication Foundation 包含大量性能计数器,可帮助您衡量应用程序的性能。有关性能计数器的详细信息,请参阅以下链接:

    https://docs.microsoft.com/en-us/dotnet/framework/wcf/diagnostics/performance-counters/

    【讨论】:

    • 非常感谢您的建议,我尝试了同样的方法,不幸的是它没有奏效。似乎这种行为是通过 WSDL 以某种方式控制的,并受到 SmartOrg 配置的限制,仍在战斗....
    • 你是对的。这些配置需要在服务器端配置。
    猜你喜欢
    • 2011-12-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-03-09
    • 1970-01-01
    相关资源
    最近更新 更多