I’m using the excellent DuplexHttpBinding. I now want to extend it so that I can use transport security with message credentials. I have some normal BasicHttpBindings set up in this mode like so:
<basicHttpBinding>
<binding name="BasicHttpBinding_Custom">
<security mode="TransportWithMessageCredential">
<message clientCredentialType="UserName"/>
</security>
</binding>
</basicHttpBinding>
However I can’t do the same thing with my DuplexHttpBinding because it doesn’t have security element.
My question is: how can I set up my DuplexHttpBinding with TransportWithMessageCredential? Or. more generally, how do you set up the message security on a binding you’ve created by inheriting from System.ServiceModel.Channels.Binding?
I’ve been struggling to find any info about this, so any links to relevant docs would be very welcome!
The solution was to add a
SecurityBindingElementas the first element in theBindingElementCollection, so in theCreateBindingElementsmethod of your binding: