Vipul
Vipul

Reputation: 1583

WCF Initiation is taking too much time

WCF service is taking around 5-6 seconds for first request there after all call execute very fast. below is the client side configuration for my WCF service.

Using IIS hosting.

        WSHttpBinding binding = new WSHttpBinding();
        binding.SendTimeout = TimeSpan.FromMinutes(1);
        binding.OpenTimeout = TimeSpan.FromMinutes(1);
        binding.CloseTimeout = TimeSpan.FromMinutes(1);
        binding.ReceiveTimeout = TimeSpan.FromMinutes(1);
        binding.AllowCookies = false;
        binding.BypassProxyOnLocal = false;
        binding.HostNameComparisonMode = HostNameComparisonMode.StrongWildcard;

        binding.MessageEncoding = WSMessageEncoding.Mtom; 

        binding.TextEncoding = System.Text.Encoding.UTF8;
        binding.UseDefaultWebProxy = true;
        binding.Name = "BasicHttpBinding_ILearningService";


        binding.Security.Mode = SecurityMode.Transport;              
        binding.Security.Transport.ClientCredentialType = HttpClientCredentialType.None;
        binding.Security.Transport.ProxyCredentialType = HttpProxyCredentialType.None;
        binding.Security.Transport.Realm = "";

Server side configuration

<services>
  <service behaviorConfiguration="LearningServiceServiceBehavior" name="LearningService">
    <host>

      <baseAddresses>
        <add baseAddress="https://xxxxx/LearningService.svc" />
      </baseAddresses>
    </host>
    <endpoint address="" binding="wsHttpBinding" bindingConfiguration="TransportSecurity" contract="ILearningSuiteService">
      <identity>
        <dns value="localhost" />
      </identity>
     </endpoint>

    <endpoint address="mex" binding="mexHttpsBinding" contract="IMetadataExchange" />
  </service>
</services>
<bindings>
  <wsHttpBinding>
    <binding name="TransportSecurity" messageEncoding="Mtom" sendTimeout="00:1:00" openTimeout="00:2:00">
      <security mode="Transport">
        <transport clientCredentialType="None" />
      </security>
    </binding>
  </wsHttpBinding>
</bindings>
<behaviors>
  <serviceBehaviors>
    <behavior name="LearningServiceServiceBehavior">
      <serviceMetadata httpsGetEnabled="true" httpGetEnabled="false" httpGetUrl="http://xxxxxxx/Metadata" httpsGetUrl="https://xxxxxxxx/Metadata" />
      <serviceDebug includeExceptionDetailInFaults="true" />
    </behavior>
  </serviceBehaviors>
</behaviors>

Upvotes: 3

Views: 1672

Answers (3)

Jack
Jack

Reputation: 715

The first time you make the call, the client sets up the connection to the server and the server does necessary authentication, this can take some time. And based on what I found in my project, the WCF serialization can take much time in the first time if your contract is huge. After that, the serialization can be much quicker.

Upvotes: 1

Richard Blewett
Richard Blewett

Reputation: 6109

The other issue you may be see is that as you are using transport security you are doing certificate validation on the client each time you create a new proxy. Is it possible the certificate validation is expensive, say, due to the revocation list for the certificate not being available in a timely fashion?

Try turning off security and see if that changes the behavior

Upvotes: 4

Richard Blewett
Richard Blewett

Reputation: 6109

Although not completely definite it looks like you are IIS hosting (I say not definite because baseAddresses are not specified by you in IIS hosting, rather the actual .svc file is the base address for the service)

Assuming you are IIS hosting are you seeing the spin up time for the worker process? Depending on which version of Windows you are using you could use Windows Server AppFabric to autostart the service before the first request

Upvotes: 2

Related Questions