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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T12:35:29+00:00 2026-06-11T12:35:29+00:00

I have workflow service with an extension that I configuration through a custom BehaviorExtensionElement.

  • 0

I have workflow service with an extension that I configuration through a custom BehaviorExtensionElement.
Since I need to reuse some configuration properties also in other pieces of my application, I would like to know how it is possible to read the configuration element through the ConfigurationManager.

public class ServiceConfigurationElement : BehaviorExtensionElement
{
    public const string RetryDelayKey = "retryDelay";

    /// <summary>
    /// Creates a behavior extension based on the current configuration settings.
    /// </summary>
    /// <returns>
    /// The behavior extension.
    /// </returns>
    protected override object CreateBehavior()
    {
        var behavior = new ServiceConfigurationBehavior
            {
                RetryDelay = this.CommsRetryDelay
            };
        return behavior;
    }

    /// <summary>
    /// Gets the type of behavior.
    /// </summary>
    /// <returns>
    /// A <see cref="T:System.Type"/>.
    /// </returns>
    public override Type BehaviorType
    {
        get
        {
            return typeof(ServiceConfigurationBehavior);
        }
    }

    [ConfigurationProperty(RetryDelayKey, IsKey = false, DefaultValue = true)]
    public TimeSpan RetryDelay
    {
        get

        {
            return (TimeSpan)this[RetryDelayKey];
        }

        set
        {
            this[RetryDelayKey] = value;
        }
    }
}

And the configuration:

<system.serviceModel>
    <behaviors>
        <serviceBehaviors>
            <behavior>
                <serviceConfiguration retryDelay="00:01:00" />
            </behavior>
        </serviceBehaviors>
    </behaviors>
    <extensions>
        <behaviorExtensions>
            <add name="serviceConfiguration" type="MyNamespace.ConfigurationElement, MyAssembly"/>
        </behaviorExtensions>
    </extensions>
</system.serviceModel>

How can I read the RetryDelay property (and others, of course) through the ConfigurationManager?

Thanks

Francesco

  • 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-11T12:35:30+00:00Added an answer on June 11, 2026 at 12:35 pm

    ConfigurationManager does not have a property explicitly for the ServiceModel section. Instead, Microsoft provided the ServiceModelSectionGroup (MSDN) which will allow you to retrieve that section to read values.

    First you will need to load the configuration file using the various ways to open it on the ConfigurationManager (MSDN). Below I use the OpenMappedExeConfiguration method.

    ExeConfigurationFileMap exeConfigurationFileMap = new ExeConfigurationFileMap
    {
        ExeConfigFilename = Assembly.GetEntryAssembly().Location + ".config"
    };
    Configuration configuration = ConfigurationManager.OpenMappedExeConfiguration( exeConfigurationFileMap, ConfigurationUserLevel.None );
    

    After that, you will need to retrieve the section by doing the following:

    ServiceModelSectionGroup serviceModelGroup = ServiceModelSectionGroup.GetSectionGroup( configuration );
    

    From there you can access any of the service model configuration values. I will modify your behavior to the following for an example. Note the named behavior.

    <behavior name="Configuration">
        <serviceConfiguration retryDelay="00:01:00" />
    </behavior>
    

    Once you have the section group, it’s just a matter of getting the behavior extensions and iterating through them, like so.

    ServiceBehaviorElementCollection serviceBehaviors = serviceModelGroup.Behaviors.ServiceBehaviors;
    
    foreach ( ServiceBehaviorElement behavior in serviceBehaviors )
    {
        if ( behavior.Name == "Configuration" )
        {
            ServiceConfigurationElement serviceConfiguration = behavior[ typeof( ServiceConfigurationElement ) ] as ServiceConfigurationElement;
            Console.WriteLine( serviceConfiguration.RetryDelay.ToString() );
            // do whatever you like here
        }
    }
    

    You’ll see that I used the ServiceBehaviors, but there is another property for the EndpointBehaviors as well. One way to extend this would be to cache the service model section group in a static variable (less disk I/O) and write a few methods to query the various attributes of any extensions you might write in the future.

    Hope this helps!

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

Sidebar

Related Questions

We have a .Net 3.5 Workflow hosted as a service that sometimes stops unexpectedly.
I have a workflow service which receives a stream through a ReceiveRequest activity. The
I have a workflow service created with WF 4.0 and the need to have
I have a custom built web service that is built to simply add items
I have a workflow inside a Windows Service that is a loop that performs
I have a workflow which has a custom activity which calls a web service.
I've a windows workflow service that is hosted in a console application. I have
I have created a workflow service to handle some business process at my company.
I have a wcf service that is hosted in IIS. This service launches some
I have a custom tracking service that has been running for a while now

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.