简体   繁体   English

WCF主机延迟15秒

[英]WCF host 15 seconds delay

I'm using .NET 3.5 and WCF for developing a server-client application. 我正在使用.NET 3.5和WCF来开发服务器 - 客户端应用程序。 Binding=BasicHttp. 绑定= BasicHttp。 I'm working and deploying the service in a windows 2003 server sp2. 我正在Windows 2003服务器sp2中部署该服务。

The service in the server is being self-hosted by a console application and in my computer everything works fine. 服务器中的服务由控制台应用程序自托管,在我的计算机中一切正常。 The thing is that when I deploy the server in the computer it should run, it takes EXACTLY 15 seconds to open the serviceHost instance, when it should be milliseconds. 问题是,当我在计算机中部署服务器时,它应该运行,打开serviceHost实例需要15秒,这应该是毫秒。 I could live with that, but also when this instance receives the first request from a client, it takes EXACTLY 15 seconds to respond, and like this with each new client. 我可以忍受这种情况,但是当这个实例收到来自客户端的第一个请求时,它只需要15秒的时间来响应,并且像每个新客户端一样。 After the first request, it takes just milliseconds to respond the following. 在第一次请求之后,响应以下内容只需几毫秒。

I'm not having this problem in my computer and I've tried in many others and it's working fine also. 我在我的计算机上没有遇到这个问题,而且我已经尝试了很多其他问题,而且工作正常。 I don't have the possibility to format the server in which I'm deploying in, so I need some advice about what can be wrong in that particular computer or configuration. 我没有可能格式化我正在部署的服务器,所以我需要一些关于特定计算机或配置中可能出错的建议。 This behavior repeats with ANY service I want to host in that machine, even the basic example in the " WCF service library " template, so for the sake of simplicity I'm working on it while I'm solving this problem. 这个行为重复我希望在该机器上托管的任何服务,甚至是“ WCF服务库 ”模板中的基本示例,所以为了简单起见,我正在解决这个问题。 This is the app.config I'm using in the host app. 这是我在主机应用程序中使用的app.config。 The rest of the code is exactly the one of the template above mentioned. 其余代码正好是上面提到的模板之一。 Please keep in mind the service is working fine, is the delay that makes the service unusable. 请记住服务正常,是延迟使服务无法使用。

Thanks in advance ! 提前致谢 !

<?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>

Client App.config: 客户端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>

Loading a ServiceHost for the first time always take a long time. 首次加载ServiceHost总是需要很长时间。 Some reasons: 一些原因:

  • Loading assemblies 装载组件
  • Opening ports 打开港口
  • JITting code JITting代码
  • Doing various reflection operations 做各种反射操作

So if your machine is not very good spec, this could be even longer. 因此,如果您的机器规格不是很好,这可能会更长。 I do not think there is anything related to how you are doing it. 我认为没有任何与你如何做有关的事情。


UPDATE UPDATE

After looking at the client config, it appears that the security used as message with clientCredentialType="Windows" will make a call to the Domain Controller which probably times out . 查看客户端配置后,看起来用作clientCredentialType="Windows"消息的安全性将调用域控制器,这可能会超时

I would start by using fiddler on the client side to see what's happening. 我将首先在客户端使用fiddler来查看正在发生的事情。 If needed you could also do netmon if there's non-http lower level networking issues. 如果需要,如果存在非http较低级别的网络问题,您也可以执行netmon。

On the server side, you can profile, trace or log to see if during that 15 second request, how much time is spent in server code. 在服务器端,您可以配置,跟踪或记录以查看在该15秒请求期间,服务器代码花费了多少时间。

Those will at least tell you where to begin. 那些至少会告诉你从哪里开始。

If it's for each clients new request, you should look at authentication, DNS names resolution and other network configs. 如果是每个客户端的新请求,您应该查看身份验证,DNS名称解析和其他网络配置。 Another good experiment would be after that 15 sec request for a user, recycle the server app and make the request again. 另一个好的实验是在15秒后请求用户,回收服务器应用程序并再次发出请求。 15 sec again? 再过15秒? If not, it's likely networking, if so, something in the app/config. 如果没有,它可能是网络,如果是这样,app / config中的东西。

A hunch - and it's nothing more - is that there's a DNS timeout somewhere resolving some network name. 预感 - 而且仅此而已 - 是在某处解决某些网络名称的DNS超时。 Does 是否

ping localhost

also give you a fifteen second delay? 还给你一个十五秒的延迟?

Similarly, perhaps something is trying to do a reverse DNS lookup on the incoming host name. 同样,也许某些东西试图对传入的主机名进行反向DNS查找。 Do your remote hosts have names that are resolveable by the server? 您的远程主机是否具有可由服务器解析的名称?

You might also want to check if there's a firewall or virus checker that's intercepting HTTP requests in some strange way when you open a connection on port 8732. 您可能还想检查是否有防火墙或病毒检查程序在端口8732上打开连接时以某种奇怪的方式拦截HTTP请求。

The problem was solved when I found out that it wasn't installed service pack 1 of .NET 3.5. 当我发现它没有安装.NET 3.5的Service Pack 1时,问题就解决了。 in the computer I was having problrems. 在电脑里我有问题。 Once I've installed it, everything started to run normally without delays. 一旦我安装它,一切都开始正常运行没有延迟。

Thanks everyone for the advices! 谢谢大家的建议! Best regards Nacho 最好的问候纳乔

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM