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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T19:45:12+00:00 2026-06-03T19:45:12+00:00

How do I get WCF to propagate the properties of Trace.CorrelationManager when it uses

  • 0

How do I get WCF to propagate the properties of Trace.CorrelationManager when it uses a different thread for the same operation?

I know that WCF doesn’t guarantee thread affinity. So basically one thread can start a request and a different thread may finish it. When I reproed this behavior, I see that the first thread has the two properties Trace.Correlation.ActivityId and Trace.Correlation.LogicalOperationStack properly set. WCF finished the operation with a different thread but the properties were not propagated.

To work around this, I might have to abandon the use of the CorrelationManager and will probably have to store the ActivityId in the OperationContext which I know is propagated to the new thread (Please correct me if I am wrong here). I don’t want to do this, since its more work of course and not as elegant as using that single property.

Any other ideas on how I can work around this? Can I tell WCF to propagte this for me somehow?

Thanks,
Mohammed

  • 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-03T19:45:14+00:00Added an answer on June 3, 2026 at 7:45 pm

    To work around this, I abandoned the use of Trace.CorrelationManager properties. As a substitute to these properties, I now use custom properties that I added to an Extension class. I can now directly modify the ActivityId and LogicalOperationStack on this extension which can be accessed for the life of any operation request which is just as convenient as using the Trace.CorrelationManager properties.

    As a plus, I can store any other custom properties I would like to use for the life of the request. A great example of this would be a customer id, or resource id, that can also be used in logging for better supportability.

    using System;
    using System.Collections;
    using System.ServiceModel;
    
    namespace MyNamespace
    {
        /// <summary>
        /// Class that represents an extension used to store custom data for the life of a WCF OperationContext.
        /// </summary>
        public class OperationContextExtension : IExtension<OperationContext>
        {
            /// <summary>The activity id of the operation.</summary>
            private Guid activityId;
    
            /// <summary>The logical operation stack of the operation.</summary>
            private Stack logicalOperationStack;
    
            /// <summary>
            /// Initializes a new instance of the OperationContextExtension class.
            /// </summary>
            public OperationContextExtension()
            {
                this.logicalOperationStack = new Stack();
            }
    
            /// <summary>
            /// Gets the current OperationContextExtension extension from the OperationContext.
            /// </summary>
            public static OperationContextExtension Current
            {
                get
                {
                    OperationContextExtension context;
                    if (OperationContext.Current == null)
                    {
                        context = null;
                    }
                    else
                    {
                        context = OperationContext.Current.Extensions.Find<OperationContextExtension>();
                    }
    
                    return context;
                }
            }
    
            /// <summary>
            /// Gets or sets the activity id for the current operation.
            /// </summary>
            public Guid ActivityId
            {
                get { return this.activityId; }
                set { this.activityId = value; }
            }
    
            /// <summary>
            /// Gets the LogicalOperationStack for the current operation.
            /// </summary>
            public Stack LogicalOperationStack
            {
                get { return this.logicalOperationStack; }
            }
    
            /// <summary>
            /// Enables an extension object to find out when it has been aggregated. Called when the extension is added 
            /// to the System.ServiceModel.IExtensibleObject Extensions property.
            /// </summary>
            /// <param name="owner">The extensible object that aggregates this extension.</param>
            public void Attach(OperationContext owner)
            {
                // Use this method for request initialization if needed
            }
    
            /// <summary>
            /// Enables an object to find out when it is no longer aggregated. Called when an extension is removed 
            /// from the System.ServiceModel.IExtensibleObject Extensions property.
            /// </summary>
            /// <param name="owner">The extensible object that aggregates this extension.</param>
            public void Detach(OperationContext owner)
            {
                // Use this method for request cleanup if needed
            }
        }
    }
    

    You will now need add this extension to the OperationContext. First, you need to find a suitable hook into a WCF behavior extension. A popular option is to use a MessageInspector applied to an IEndpointBehavior. Here are some great reads on how to achieve this (A quick search will yield many useful examples if mine don’t help):

    • Extending WCF with Custom Behaviors
    • Configuring and Extending the Runtime with Behaviors
    • Endpoint Behavior (ApplyDispatchBehavior) Example

    Once you have your hook, you want to add your Extension to the OperationContext as soon as you can with the following line:

    // Add an extension object to the current operation context to track custom state across all threads
    // for the life of the operation
    OperationContext.Current.Extensions.Add(new OperationContextExtension());
    

    Now you can access your ActivityId property and LogicalOperationStack, or any other property you define in this class from virtually anywhere in your code work flow:

    LogOperation(OperationContextExtension.Current.ActivityId, logMessage);
    OperationContextExtension.Current.LogicalOperationStack.Push("Starting 'Nested Activity' 3...");
    

    Hope this helps!

    -Mohammed

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

Sidebar

Related Questions

I am trying to get a WCF service to return a List that contains
I have an AJAX call that I want to run against a WCF GET
I have WCF connector that should get some small amount of data for me,
I'm wanting to get a WCF-over-TCP service working. I was having some problems with
I am attempting to get the WCF Rest Service Template 40 (CS) which is
I get a CommunicationException while using WCF service. The message is: The remote endpoint
How can I to get list of all wcf services running on a machine?
When consuming a .NET WCF webservice I get the following response (error): Unsupported HTTP
I get an error on the client for my wcf service hosted by my
Im trying to get an image from a wcf rest service like so: [ServiceContract]

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.