我有一个带有扩展的工作流服务,我通过自定义 BehaviorExtensionElement 进行配置。由于我还需要在我的应用程序的其他部分中重用一些配置属性,我想知道如何通过 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;
}
}
}
和配置:
<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>
如何通过 ConfigurationManager 读取 RetryDelay 属性(当然还有其他属性)?
谢谢
弗朗切斯科