簡體   English   中英

WCF主機延遲15秒

[英]WCF host 15 seconds delay

我正在使用.NET 3.5和WCF來開發服務器 - 客戶端應用程序。 綁定= BasicHttp。 我正在Windows 2003服務器sp2中部署該服務。

服務器中的服務由控制台應用程序自托管,在我的計算機中一切正常。 問題是,當我在計算機中部署服務器時,它應該運行,打開serviceHost實例需要15秒,這應該是毫秒。 我可以忍受這種情況,但是當這個實例收到來自客戶端的第一個請求時,它只需要15秒的時間來響應,並且像每個新客戶端一樣。 在第一次請求之后,響應以下內容只需幾毫秒。

我在我的計算機上沒有遇到這個問題,而且我已經嘗試了很多其他問題,而且工作正常。 我沒有可能格式化我正在部署的服務器,所以我需要一些關於特定計算機或配置中可能出錯的建議。 這個行為重復我希望在該機器上托管的任何服務,甚至是“ WCF服務庫 ”模板中的基本示例,所以為了簡單起見,我正在解決這個問題。 這是我在主機應用程序中使用的app.config。 其余代碼正好是上面提到的模板之一。 請記住服務正常,是延遲使服務無法使用。

提前致謝 !

<?xml version="1.0" encoding="utf-8" ?>
<configuration>

  <system.web>
    <compilation debug="true" />
  </system.web>
  <!-- When deploying the service library project, the content of the config file must be added to the host's 
  app.config file. System.Configuration does not support config files for libraries. -->
  <system.serviceModel>
    <services>
      <service name="WcfServiceLibrary7.Service1" behaviorConfiguration="WcfServiceLibrary7.Service1Behavior">
        <host>
          <baseAddresses>
            <add baseAddress = "http://localhost:8732/Design_Time_Addresses/WcfServiceLibrary7/Service1/" />
          </baseAddresses>
        </host>
        <!-- Service Endpoints -->
        <!-- Unless fully qualified, address is relative to base address supplied above -->
        <endpoint address ="" binding="wsHttpBinding" contract="WcfServiceLibrary7.IService1">
          <!-- 
              Upon deployment, the following identity element should be removed or replaced to reflect the 
              identity under which the deployed service runs.  If removed, WCF will infer an appropriate identity 
              automatically.
          -->
          <identity>
            <dns value="localhost"/>
          </identity>
        </endpoint>
        <!-- Metadata Endpoints -->
        <!-- The Metadata Exchange endpoint is used by the service to describe itself to clients. --> 
        <!-- This endpoint does not use a secure binding and should be secured or removed before deployment -->
        <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
      </service>
    </services>
    <behaviors>
      <serviceBehaviors>
        <behavior name="WcfServiceLibrary7.Service1Behavior">
          <!-- To avoid disclosing metadata information, 
          set the value below to false and remove the metadata endpoint above before deployment -->
          <serviceMetadata httpGetEnabled="True"/>
          <!-- To receive exception details in faults for debugging purposes, 
          set the value below to true.  Set to false before deployment 
          to avoid disclosing exception information -->
          <serviceDebug includeExceptionDetailInFaults="False" />
        </behavior>
      </serviceBehaviors>
    </behaviors>
  </system.serviceModel>

</configuration>

客戶端App.config:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
    <system.serviceModel>
        <bindings>
            <wsHttpBinding>
                <binding name="WSHttpBinding_IService1" closeTimeout="00:01:00"
                    openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
                    bypassProxyOnLocal="false" transactionFlow="false" hostNameComparisonMode="StrongWildcard"
                    maxBufferPoolSize="524288" maxReceivedMessageSize="65536"
                    messageEncoding="Text" textEncoding="utf-8" useDefaultWebProxy="true"
                    allowCookies="false">
                    <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
                        maxBytesPerRead="4096" maxNameTableCharCount="16384" />
                    <reliableSession ordered="true" inactivityTimeout="00:10:00"
                        enabled="false" />
                    <security mode="Message">
                        <transport clientCredentialType="Windows" proxyCredentialType="None"
                            realm="" />
                        <message clientCredentialType="Windows" negotiateServiceCredential="true"
                            algorithmSuite="Default" />
                    </security>
                </binding>
            </wsHttpBinding>
        </bindings>
        <client>
            <endpoint address="http://localhost:8732/Design_Time_Addresses/WcfServiceLibrary7/Service1/"
                binding="wsHttpBinding" bindingConfiguration="WSHttpBinding_IService1"
                contract="ServiceReference1.IService1" name="WSHttpBinding_IService1">
                <identity>
                    <dns value="localhost" />
                </identity>
            </endpoint>
        </client>
    </system.serviceModel>
</configuration>

首次加載ServiceHost總是需要很長時間。 一些原因:

  • 裝載組件
  • 打開港口
  • JITting代碼
  • 做各種反射操作

因此,如果您的機器規格不是很好,這可能會更長。 我認為沒有任何與你如何做有關的事情。


UPDATE

查看客戶端配置后,看起來用作clientCredentialType="Windows"消息的安全性將調用域控制器,這可能會超時

我將首先在客戶端使用fiddler來查看正在發生的事情。 如果需要,如果存在非http較低級別的網絡問題,您也可以執行netmon。

在服務器端,您可以配置,跟蹤或記錄以查看在該15秒請求期間,服務器代碼花費了多少時間。

那些至少會告訴你從哪里開始。

如果是每個客戶端的新請求,您應該查看身份驗證,DNS名稱解析和其他網絡配置。 另一個好的實驗是在15秒后請求用戶,回收服務器應用程序並再次發出請求。 再過15秒? 如果沒有,它可能是網絡,如果是這樣,app / config中的東西。

預感 - 而且僅此而已 - 是在某處解決某些網絡名稱的DNS超時。 是否

ping localhost

還給你一個十五秒的延遲?

同樣,也許某些東西試圖對傳入的主機名進行反向DNS查找。 您的遠程主機是否具有可由服務器解析的名稱?

您可能還想檢查是否有防火牆或病毒檢查程序在端口8732上打開連接時以某種奇怪的方式攔截HTTP請求。

當我發現它沒有安裝.NET 3.5的Service Pack 1時,問題就解決了。 在電腦里我有問題。 一旦我安裝它,一切都開始正常運行沒有延遲。

謝謝大家的建議! 最好的問候納喬

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM