Create a custom binding that is custom on top of App.config
I have created a custom binding and want to make it customizable via App.config.
The binding currently has no special options, so it would only be sufficient to support
<endpoint address="http://myAddress"
binding="myBinding"
contract="myContract">
After checking some sites, I found out that I need to enable configuration support via <BindingExtension>
. However, the MSDN site did not help much, as when I try to add
<extensions>
<bindingExtensions>
<add name="myBinding"
type="MyNamespace.MyHttpBinding, NameOfMyDll, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null"/>
</bindingExtensions>
</extensions>
I only get the following error when I try to run the program:
Configuration binding extension 'system.serviceModel / bindings / myBinding' not found. Make sure this binding extension is registered correctly in system.serviceModel / extensions / bindingExtensions and is written correctly.
The type mentioned in bindingExtension indicates the type that inherits from Binding
.
What do I need to add to enable configuration support for my binding?
My goal is to just export my binding to a config file. I don't want to allow any special settings for the binding. It should only be used via the <endpoint>
config file tag .
source to share
You are on the right track. However, the key point is that the bindingExtension element should not point directly to your own binding class.
Instead, you need to have multiple classes that support the configuration model. For starters, the bindingExtension that you register is indeed a class that inherits from StandardBindingCollectionElement . This is a set of StandardBindingElement , which is a configuration class that has all the configuration properties that your binding will maintain in the .config file and will be responsible for instantiating the Binding and setting any properties that were set in the .config file on it.
Also note that generally, you should follow a similar pattern to create a configuration view of your TransportBindingElement (if you are making a transport channel) so that you can create your own bindings using it, albeit with customization. In this case, you will have a class that inherits TransportElement .
PS If you think that this is a lot of repetitive code, if you have a lot of settings, I agree.
Update: . Found your problem: you need at least empty <bindings /> in your config file. Just add it and the binding will now be recognized.
source to share