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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T16:11:56+00:00 2026-06-11T16:11:56+00:00

I have two Methods in a WCF Service say Method1() { _currentValue = 10;

  • 0

I have two Methods in a WCF Service say

Method1()
{
 _currentValue = 10;
}

Method2()
{
return _currentValue;
}

I have a situation in which, i need to set a value in Method1() and read it in Method2().

I tried using static variable like public static int _currentValue, i could able to read the value set in Method1() in Method2().

But the issue is, i want this variable to react like separate instance variable for each request made. i.e., right now below is the problem

Browser 1 :

 - Method1() is called
    => sets _currentValue = 10;
 - Method2() is called
    => returns _currentValue = 10;

Browser 2:

 - Method2() is called
    => returns _currentValue = 10;

Actually the value set is Browser 1 is static, so in Browser 2
the same value is retrieved.

What i am trying to implement is the variable should act like a new instance for each request made (when calling from each browser). What should i use in this case? a session?

  • 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-11T16:11:57+00:00Added an answer on June 11, 2026 at 4:11 pm

    You’re going to need some mechanism for correlation because you have two completely different sessions calling into different methods. So I would recommend using a private key that both callers know.

    It is a bit impossible for me to know what that key can be because I can’t really gather anything from your question, so only you know that, but the simple fact is you’re going to need correlation. Now, once you determine what they can use you can do something like this.

    public class SessionState
    {
        private Dictionary<string, int> Cache { get; set; }
    
        public SessionState()
        {
            this.Cache = new Dictionary<string, int>();
        }
    
        public void SetCachedValue(string key, int val)
        {
            if (!this.Cache.ContainsKey(key))
            {
                this.Cache.Add(key, val);
            }
            else
            {
                this.Cache[key] = val;
            }
        }
    
        public int GetCachedValue(string key)
        {
            if (!this.Cache.ContainsKey(key))
            {
                return -1;
            }
    
            return this.Cache[key];
        }
    }
    
    public class Service1
    {
        private static sessionState = new SessionState();
    
        public void Method1(string privateKey)
        {
            sessionState.SetCachedValue(privateKey, {some integer value});
        }
    
        public int Method2(string privateKey)
        {
            return sessionState.GetCachedValue(privateKey);
        }
    }
    
    • 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 which has two methods exposed: Note: The wcf service
I have a WCF service with three methods. Two of the methods return custom
I have a WCF services. Which has two methods, say Get and Save. I
I have a WCF service ( Let's say WCFService1 ) is deployed on two
My program is a WCF service which publishes several methods and have multiple client.
I have self hosted net tcp WCF service that exposes two methods and the
I'm hosting my first WCF service in IIS. I have two methods, 1 to
I have a WCF service with two methods, Ping and PutAddress. Ping works fine,
I have two methods, one called straight after another, which both throw the exact
lets say I have two methods in my controller to support both json and

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.