When you created your own binding in the code, did you also implement “YourBindingElement” (obtained from StandardBindingElement) and “YourBindingCollectionElement” (obtained from StandardBindingCollectionElement) with it?
If so, use this to customize your custom binding, as if it were any other binding.
The first step is to register your binding in the app.config or web.config file in the <system.serviceModel> extensions section
<extensions> <bindingExtensions> <add name="yourBindingName" type="YourBinding.YourBindingCollectionElement, YourBindingAssembly" /> </bindingExtensions> </extensions>
Your new binding is now registered as a “normal” available binding in WCF. Define your specifics in the bindings section, as with other bindings:
<bindings> <yourBinding> <binding name="yourBindingConfig" proxyAddress="...." useDefaultWebProxy="false" /> </yourBinding> </bindings>
Specify other parameters here as defined in your class "... BindingElement".
Finally, use the binding as a normal binding in your services and / or client sections in system.serviceModel:
<client> <endpoint address="....your url here......" binding="yourBinding" bindingConfiguration="yourBindingConfig" contract="IYourContract" name="YourClientEndpointName" /> </client>
I could not find many resources on how to write my own binding in code on the Internet. Microsoft has a WCF / WPF / WF sample kit that includes several samples, from which I basically learned enough to understand this :-)
There's a really nice article in Michele Leroux Bustamante 's article on creating your custom bindings - part 2 of the series, but part 1 is not publicly available:
Here is an example of custom binding in code for which you can download the full source code: ClearUserNameBinding .
Mark