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

  • SEARCH
  • Home
  • 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 7993111
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T13:45:14+00:00 2026-06-04T13:45:14+00:00

I have a WCF web service hosted on IIS 7. This web service serves

  • 0

I have a WCF web service hosted on IIS 7. This web service serves up JSON content for use in mobile apps. It uses the Entity Framework on top of MS SQL 2005, and the Interface contract looks like the below:

   [ServiceContract]
    public interface MyService
    {
        [WebInvoke(Method = "GET", UriTemplate = "/GetStuff?skip={skip}&take={take}&loanAmt={loanAmt}&propertyVal={propertyVal}&Term={Term}&MonthlyRent={MonthlyRent}", RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json)]
        [OperationContract]
        ProductsDTO GetProducts(int skip, int take, decimal loanAmt, decimal propertyVal, int Term, decimal MonthlyRent);
    }

The implementation looks like this:

    public ProductsDTO GetProducts(int skip, int take, decimal loanAmt, decimal propertyVal, int Term, decimal MonthlyRent)
    {
       //Some set up code
      using (MyEntities context = new MyEntities()) 
        {
              //Get our products
        }

     return ReturnedList
    }

On the first run of this, it can take anywhere up to 15 seconds (unacceptable for a mobile app), on subsequent runs, the data comes back in under a second. After 5 minutes of inactivity, the WCF service reverts to taking 15 seconds to start.

I initially thought the bottle neck was at IIS7 and thought my App Pool was shutting off. After setting the App Pool to never recycle and studying w3wp.exe processes on the IIS server, I realized this was not the case. It is the database session that is shutting off after those five minutes.

This being the case, I want to hold a SQL session open to immediately serve up requests from the WCF application, however, I don’t want to set the Entity Context as a singleton or leave this open in the service as I understand this is poor practise. I could pass a SQL connection object TO the context (using (MyEntities context = new MyEntities(MySQLConnection))) and hold that open? Or can someone suggest something else?

I had seen lots of posts with scripts that touch the web service to keep it alive which gave me the creeping horrors, so have avoided going down this route.

What are your thoughts?

Update 1

As per Andomars response, I have added the following initialization code to the WCF service.

   public Service1()
        {
            // Blocking call that initializes
            // the service instance
            this.Initialize();
        }

        BackgroundWorker KeepSQLAlive = new BackgroundWorker();

        private void Initialize()
        {
            KeepSQLAlive.DoWork += new DoWorkEventHandler(KeepSQLAlive_DoWork);

            KeepSQLAlive.RunWorkerAsync();
        }

        void KeepSQLAlive_DoWork(object sender, DoWorkEventArgs e)
        {
            Timer pingback = new Timer(180000);

            pingback.Elapsed += new ElapsedEventHandler(pingback_Elapsed);

            pingback.Start();
        }

        void pingback_Elapsed(object sender, ElapsedEventArgs e)
        {
            using (MyEntities context = new MyEntities ())
            {
                context.ExecuteStoreCommand("select @@servername");
            }
        }

This feels like a bit of a fudge, and I’m a bit worried without creating the service as a singleton the service will continue to spawn SQL sessions without ever killing any. However, if it works it is the path of least resistance as hosting this code in a windows service would take more time and I am unclear how to integrate this in with IIS security (I want to use SSL). I will report back whether the above works. (thanks for the assistance all)

  • 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-06-04T13:45:16+00:00Added an answer on June 4, 2026 at 1:45 pm

    You could add a background thread that runs select @@servername (or another trivial query) every minute. That should keep the connection pool warm.

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

Sidebar

Related Questions

I have a simple WCF Web service. It's hosted on IIS under the default
I have a WCF web service, which I have hosted in IIS on my
I have an IIS hosted WCF service (configured as described in this blog post
I have a WCF web service using basicHttpBinding with NTLM hosted on IIS 7
I have a WCF web service, and I want to use Basic authentication. I
I have a website that talks to a remote WCF web service. Both use
I have a web service implemented in WCF. This service is only going to
I have a WCF service (.NET 4) hosted in IIS. My service contract has
I have a Silverlight application using a WCF service hosted in IIS. I make
I have a REST WCF service that is being hosted in IIS. I have

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.