I'm writing a custom WCF binding that would like to control using configuration. To be clear, I'm not talking about using the standard <customBinding>
element, but rather inheriting from Binding
and writing a full class.
My binding isn't very complicated, and I really only have one property that I would like to set through config, useSsl
. However, I am having difficulty getting .NET to recognize my configuration attribute even though I believe I have everything in order.
Binding
public class MyCustomBinding : Binding {
public MyCustomBinding() {
// Initialization
}
private bool _useSsl;
public bool UseSsl {
get { return _useSsl; }
set { _useSsl = value; }
}
// Remaining implementation omitted
}
Binding Configuration Element
public class MyCustomBindingElement : StandardBindingElement {
protected override Type BindingElementType {
return typeof(MyCustomBinding);
}
// public const string UseSsl = "useSsl"
[ConfigurationProperty(ConfigurationStrings.UseSsl, DefaultValue: true)]
public bool UseSsl {
get { return (bool)this[ConfigurationStrings.UseSsl]; }
set { this[ConfigurationStrings.UseSsl] = value; }
}
// Remaining implementation omitted
}
Binding Configuration Collection Element
public class MyCustomBindingCollectionElement
: StandardBindingCollectionElement<MyCustomBinding, MyCustomBindingElement> {}
I've registered the collection element in my web.config file:
<extensions>
<bindingExtensions>
<add name="myCustomBinding" type="MyCustomWcf.MyCustomBindingCollectionElement, MyCustomWcf"/>
</bindingExtensions>
</extensions>
Then in my <bindings>
section I add an instance of my custom binding.
<myCustomBinding>
<binding useSsl="false" />
</myCustomBinding>
However, I receive the following configuration exception at runtime:
Unrecognized attribute 'useSsl'. Note that attribute names are case-sensitive
If I do not specify any properties on my binding, then it works. What am I doing wrong here?