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 5952823
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T17:44:12+00:00 2026-05-22T17:44:12+00:00

In a WCF Service, I need to create a variable which should be accessible

  • 0

In a WCF Service, I need to create a variable which should be accessible anytime from anywhere. All methods of my service need to have access to that data and I can load it only once. So I though about using a static variable in the Global.asax.cs. However I am not sure to understand what is going to be the scope of that variable. Is that data is going to be used for all the requests? My understanding is that it should because the same static variable should be used across the App Domain. Is that correct?

public static IList<MyData> Data { get; set; } 
private static IList<MyData> Load() 
{
    return Big data struct from DB.
}

protected void Application_Start(object sender, EventArgs e)
{
    Data = Load();
}

Finally, is there a better way to achieve that? I am not a big fan of static variable…

  • 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-22T17:44:12+00:00Added an answer on May 22, 2026 at 5:44 pm

    You could use an application variable:

    public static IList<MyData> Data {
        get
        {
            if (Application["MyIListData"] != null)
                return (IList<MyData>)Application["MyIListData"];
            else
                return new IList<MyData>();
        }
        set
        {
            Application["MyIListData"] = value;    
        }
    } 
    
    protected void Application_Start(object sender, EventArgs e)
    {
        Data = Load();
    }
    

    Not really much different in actual implementation except that now it’s available globally through that variable name as an application variable.

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

Sidebar

Related Questions

I have a WCF service. now, I need to create a client that consumes
I have a Windows Service Application in which i create WCF services in it.
I have a need to connect to a WCF service I wrote without having
I need to create a WCF service that only allows a single client at
I am trying to create a WCF Streaming Service. I have two requirements that
i wish to create a repository pattern but with a WCF Rest Service which
I have a WCF data service with some methods I call asynchronously during page_load
I need to create wcf service for sharepoint 2010. The idea to use Jquery
I need a guide on how to create a wcf service inside an existing
I have written a .NET Windows service which has a WCF service built into

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.