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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T02:55:25+00:00 2026-05-25T02:55:25+00:00

I have re-worded my question. From the server side code of my WCF services,

  • 0

I have re-worded my question.

From the server side code of my WCF services, I would like to cache a few variables. These variables need to be used through out the livecycle of one service call. I don’t want them in every method signature call that may be used in the services logic.

If it was a web applicaiton I would use session management, but this is on the server code side. How do I ‘cache’ these values, per service call, and then dispose of them on service completion?

Solution:

The point of this was to track which service call had a error in a bug tracking tool. So in the end I did something like the following:

  public class MyService: IMyService
    {
         public String ServiceLogic(string var1, string var2, string id)
         {
             try{
                    DoingStuff.DoMoreStuff();
             }
             catch(exception ex)
             {
                 var trapper = MyCustomErrorTrap(var1,var2);
                 throw new faultexpection<MyCustomErrorTrap>(trapper);
             }
         }

}



Public static class DoingStuff
{
     public static void DoMoreStuff()
     {
         try{
             if(blah.toString())
             ........
         }
         catch(exception ex)
         {
            throw;
          }
     } 
}

Allowing the main calling method to trap all exceptions, I can then use the two variables that I need at the top level.

  • 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-25T02:55:26+00:00Added an answer on May 25, 2026 at 2:55 am

    Your question doesn’t really make sense to me.

    through out the livecycle of one service call

    A “service call” – or a service operation – is just an invocation of a method within a service. You obviously need to pass the values in when the operation is called (or retrieve them from somewhere), so you’ll already have them.

    public class MyService : IMyContract
    {
        public void DoSomething(string p1, int p2)
        {
            DoThing(p1);
            DoAnotherThing(p2);
        }
    }
    

    So why do the parameters need to be cached? Just use them within the context as required.

    If you mean cached per session, that makes more sense. The solution is relatively simple:

    // decorate your class like this
    [ServiceBehavior(InstanceContextMode = InstanceContextMode.PerSession)]
    public class MyService : IMyContract
    {
        // these fields will persist until the session is closed
        private string _p1;
        private int _p2;
    
        public void DoSomething(string p1, int p2)
        {
            _p1 = p1;
            _p2 = p2;         
        }
    
        // check that the _p1 and _p2 values are initialised before use
        public void AnotherServiceOperation()
        {
            DoThing(_p1);
            DoAnotherThing(_p2);
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been using Anthem.NET in ASP.NET 2.0 projects for a few side projects
I have added some server side validation to a dropdown box on one of
I would love to hear ideas on how to best move code from development
I have a production system that uses ActiveMQ (5.3.2) to send messages from server
I have an application where a client communicates with a server side through REST.
A question to maybe some who have worked extensively with WinUSB APIs or user
I have worked a bit with Django and I quite like its project/applications model
My question is very similar to these two: C# component events? C# - writing
Learning from my broad question here ... I was wondering how I could go
I have android code that uses a background process to routinely (e.g. hourly) connect

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.