【问题标题】:WCF Service BehaviorWCF 服务行为
【发布时间】:2013-01-03 11:15:22
【问题描述】:

我有一个在 Windows 服务中托管的自托管 WCF 服务。我的绑定设置为 basicHttpBinding。

当我运行服务时,我运行 netsh http show servicestate 并且我看到我的服务正在监听;但是,我似乎无法正确配置参数。

当托管在 IIS 下时,它的执行速度会慢 20%,所以我想自己托管。如何配置我的自托管 WCF 服务的参数以匹配 IIS?我特别关注的参数是超时、最大连接数、超时和最大请求​​数。我试图提出服务行为;但是,它什么也没做。我在 HTTP/Parameters 下的注册表中添加了 MaxConnections 也没有运气。任何帮助表示赞赏。

这是托管在 IIS 下时的输出:

Server session ID: F9000000200015DA

    Version: 2.0
    State: Active
    Properties:
        Max bandwidth: 4294967295
        Timeouts:
            Entity body timeout (secs): 120
            Drain entity body timeout (secs): 120
            Request queue timeout (secs): 65535
            Idle connection timeout (secs): 120
            Header wait timeout (secs): 120
            Minimum send rate (bytes/sec): 240
    URL groups:
    URL group ID: F600000040001737
        State: Active
        Request queue name: MyService
        Properties:
            Max bandwidth: inherited
            Max connections: 4294967295
            Timeouts:
                Entity body timeout (secs): 120
                Drain entity body timeout (secs): 120
                Request queue timeout (secs): 65535
                Idle connection timeout (secs): 120
                Header wait timeout (secs): 0
                Minimum send rate (bytes/sec): 0
            Logging information:
                Log directory: C:\inetpub\logs\LogFiles\W3SVC2
                Log format: 0
            Authentication Configuration:
                Authentication schemes enabled:
            Number of registered URLs: 1
            Registered URLs:
                HTTP://*:80/

Request queues:
    Request queue name: MyService
        Version: 2.0
        State: Active
        Request queue 503 verbosity level: Basic
        Max requests: 3000
        Number of active processes attached: 1
        Controller process ID: 1400
        Process IDs:

这是我自托管时的输出:

Server session ID: FC00000120000229

    Version: 2.0
    State: Active
    Properties:
        Max bandwidth: 4294967295
        Timeouts:
            Entity body timeout (secs): 120
            Drain entity body timeout (secs): 120
            Request queue timeout (secs): 120
            Idle connection timeout (secs): 120
            Header wait timeout (secs): 120
            Minimum send rate (bytes/sec): 150
    URL groups:
    URL group ID: FB000001400005DE
        State: Active
        Request queue name: Request queue is unnamed.
        Properties:
            Max bandwidth: inherited
            Max connections: inherited
            Timeouts:
                Timeout values inherited
            Number of registered URLs: 1
            Registered URLs:
                HTTP://+:80/MyService/

Request queues:
    Request queue name: Request queue is unnamed.
        Version: 2.0
        State: Active
        Request queue 503 verbosity level: Basic
        Max requests: 1000

这是我的服务配置文件:

<?xml version="1.0"?> <configuration>   <system.serviceModel>
    <behaviors>
      <serviceBehaviors>
        <behavior name="MyThrottle">
          <serviceThrottling maxConcurrentCalls="3000" maxConcurrentSessions="3000"
            maxConcurrentInstances="12500" />
        </behavior>
      </serviceBehaviors>
    </behaviors>
    <bindings>
      <basicHttpBinding>
        <binding name="MyConfig" closeTimeout="00:10:00"
          openTimeout="00:10:00" receiveTimeout="00:10:00" sendTimeout="00:10:00"
          maxReceivedMessageSize="10485760" useDefaultWebProxy="false">
          <readerQuotas maxDepth="999999999" maxStringContentLength="999999999"
            maxArrayLength="999999999" maxBytesPerRead="999999999" maxNameTableCharCount="999999999" />
          <security mode="None">
            <transport clientCredentialType="None" />
          </security>
        </binding>
      </basicHttpBinding>
    </bindings>
    <services>
      <service behaviorConfiguration="MyThrottle" name="This.MyService">
        <endpoint address="http://localhost:80/MyService" binding="basicHttpBinding"
          bindingConfiguration="MyConfig" name="MyService"
          contract="This.IMyService" />
      </service>
    </services>   </system.serviceModel> </configuration>

【问题讨论】:

  • 你能展示你执行自托管的代码吗?
  • ServiceHost serverSyncHost = new ServiceHost(typeof(This.MyService)); serverSyncHost.Faulted += new EventHandler(serverSyncHost_Faulted); serverSyncHost.Open();
  • 所以问题是您在配置文件中拥有您需要的所有设置,但是当您在 Windows 服务中托管服务时它们没有应用?
  • 经过数小时的研究;我认为我没有做的是设置 HTTP.SYS 驱动程序的最大请求。在 IIS 下托管时,这是在应用程序池中设置的。自我托管时,我不确定在哪里设置。简单的答案是 IIS 下的主机;但是,在进行性能测试时,自托管的速度要快 20%。

标签: wcf wcf-binding http.sys


【解决方案1】:

以下是 Microsoft HTTP.SYS 团队的官方回复:

“Max Connections” = HttpServerConnectionsProperty 输出与“Max Requests” = HttpServerQueueLengthProperty 的含义不同。

HttpListener 不允许您为 URL 组设置 Max Connections 属性 (HttpServerConnectionsProperty) 或为请求队列设置 Max requests 属性 (HttpServerQueueLengthProperty),因此 WCF 在通过代码自托管时无法设置 http.sys 设置。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-01-12
    • 2021-10-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-26
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多