2013-01-20 100 views
2

我有一個自我託管的WCF服務,我在Windows服務中託管。我的綁定設置爲basicHttpBinding。WCF服務行爲

當我運行該服務時,我運行netsh http show servicestate並且我看到我的服務正在偵聽;但是,我似乎無法正確配置參數。

當在IIS下託管時,它執行速度慢了20%左右,所以我想自行託管。如何配置我自己託管的WCF服務的參數以匹配IIS?我特別關注的參數是超時,最大連接數,超時和最大請求​​數。我試圖把服務行爲;但是,它什麼都不做。我已經在HTTP /參數下的註冊表中添加了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> 
+0

您可以顯示代碼執行自託管的位置嗎? – Tim

+0

'ServiceHost serverSyncHost = new ServiceHost(typeof(This.MyService)); serverSyncHost.Faulted + = new EventHandler(serverSyncHost_Faulted); serverSyncHost.Open();' –

+0

所以問題是你在配置文件中有你需要的所有設置,但是當你在Windows服務中託管你的服務時它們不會被應用? –

回答

0

以下是來自Microsoft HTTP.SYS團隊的官方回覆:

「Max Connections」= HttpServerConnectionsProperty輸出的含義與「Max Requests」= HttpServerQueueLengthProperty的含義不同。

HttpListener不允許爲URL組設置最大連接屬性(HttpServerConnectionsProperty)或請求隊列的最大請求屬性(HttpServerQueueLengthProperty),因此當通過代碼進行自託管時,WCF不能設置http.sys設置。