繁体   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