简体   繁体   中英

WCF host 15 seconds delay

I'm using .NET 3.5 and WCF for developing a server-client application. Binding=BasicHttp. I'm working and deploying the service in a windows 2003 server 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. 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. 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. This is the app.config I'm using in the host app. 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:

<?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. Some reasons:

  • Loading assemblies
  • Opening ports
  • JITting code
  • 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

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 .

I would start by using fiddler on the client side to see what's happening. If needed you could also do netmon if there's non-http lower level networking issues.

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.

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. Another good experiment would be after that 15 sec request for a user, recycle the server app and make the request again. 15 sec again? If not, it's likely networking, if so, something in the app/config.

A hunch - and it's nothing more - is that there's a DNS timeout somewhere resolving some network name. 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. 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.

The problem was solved when I found out that it wasn't installed service pack 1 of .NET 3.5. 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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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