Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5839989
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T11:40:19+00:00 2026-05-22T11:40:19+00:00

I’m pretty much new at WCF and have a performance question. I have the

  • 0

I’m pretty much new at WCF and have a performance question. I have the following code that is executing at the client:

    try
    {
      for (int i = 0; i < 20; i++)
      {
         stopwatch.Reset();
         stopwatch.Start();

         var psn = client.GetPsnByPsnId(21);
         var psnList = client.GetPsnBySmartBizClientId(2);
         var container = client.GetContainerByContainerId(3);
         var containerList = client.GetContainerBySmartBizClientId(2);

         stopwatch.Stop();
         Console.WriteLine(string.Format("Pass # {0} completed in {1} milliseconds", i + 1,stopwatch.ElapsedMilliseconds));
     }
   }
   catch (FaultException exception)
   {
      MessageBox.Show(string.Format("Error occurred. The error message is {0}", exception.Message));
   }
   finally
   {
      client.Close();
      client = null;
   }

This code hits a WCF service that is hosted as a Windows service using HTTP binding under .NET 4.0. The problem I have is this. The very first time through the loop, on the very first WCF call (client.GetPsnByPsnID()), there is a very significant delay, 10+ seconds in fact. But, after this first call, each subsequent call, each time through the loop, takes < 1 second, as I would expect. I’m sure this is a WCF issue because if I call the first method outside of WCF, I get < 1 second performance.

Anyone have any idea what might be causing the initial delay?

EDIT: Here is the OnStart code for the Windows Service:

protected override void OnStart(string[] args)
{
   serviceHost = new ServiceHost(typeof(ServiceMethods),new Uri("http://111.111.111.111:1111/Psn"));

   // Add an endpoint and the methods the endpoint will support.
   serviceHost.AddServiceEndpoint(typeof(IServiceMethods), WcfConfiguration.GenerateBinding(Enumerations.WcfBindingType.HTTP), "");

   WcfConfiguration.CreateMexData(serviceHost);
   serviceHost.Open();
}

And here is the GenerateBinding method:

public static System.ServiceModel.Channels.Binding GenerateBinding(Enumerations.WcfBindingType bindingType)
{
   System.ServiceModel.Channels.Binding binding = null;

   BasicHttpBinding httpBinding = new BasicHttpBinding();
   httpBinding.Security.Mode = ((bindingType == Enumerations.WcfBindingType.HTTP) ? BasicHttpSecurityMode.None : BasicHttpSecurityMode.Transport);
   httpBinding.OpenTimeout = new TimeSpan(0, 0, 30);
   httpBinding.SendTimeout = new TimeSpan(0, 0, 30);
   httpBinding.ReceiveTimeout = new TimeSpan(0, 0, 30);
   httpBinding.Security.Transport.ClientCredentialType = HttpClientCredentialType.None;
   httpBinding.ReaderQuotas.MaxStringContentLength = httpBinding.ReaderQuotas.MaxStringContentLength;
   httpBinding.MaxReceivedMessageSize = httpBinding.MaxReceivedMessageSize;
   httpBinding.ReaderQuotas.MaxArrayLength = 1048576;
   httpBinding.MaxBufferSize = httpBinding.MaxBufferSize;

   binding = httpBinding;
   break;
   }
   return binding;
}

public static void CreateMexData(ServiceHost host)
{
  ServiceMetadataBehavior behavior = new ServiceMetadataBehavior();

  behavior.HttpGetEnabled = true;
  host.Description.Behaviors.Add(behavior);
  host.AddServiceEndpoint(typeof(IMetadataExchange), MetadataExchangeBindings.CreateMexHttpBinding(), "mex");
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T11:40:20+00:00Added an answer on May 22, 2026 at 11:40 am

    If the service is not getting any hits in between your test runs, it may actually be shutting down the WCF service application, and when a new request comes in it totally restarts the app, also taking more time. This can be changed in IIS settings (assuming you’re hosting in IIS) so that Worker processes either take longer to shutdown, or don’t shutdown at all.

    Also, WCF is making the TCP/Http Connection on your first call, subsequent calls are likely using pooled connections. Not having to reestablish the TCP/Http connection saves you a bunch of time.

    Finally, With your current implementation, best case scenario you’re still doing 4 server round-trips per iteration. You would probably be better served by batching your wcf calls together to reduce round-trips.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

That's pretty much it. I'm using Nokogiri to scrape a web page what has
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
I have a French site that I want to parse, but am running into
link Im having trouble converting the html entites into html characters, (&# 8217;) i
this is what i have right now Drawing an RSS feed into the php,
I have just tried to save a simple *.rtf file with some websites and
Seemingly simple, but I cannot find anything relevant on the web. What is the
Does anyone know how can I replace this 2 symbol below from the string
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I want to count how many characters a certain string has in PHP, but

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.