开发者

WCF How can I set clientCredentialType on custom binding

开发者 https://www.devze.com 2023-01-07 14:46 出处:网络
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:

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 Transpor开发者_如何学GotWithMessageCredential? 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 SecurityBindingElement as the first element in the BindingElementCollection, so in the CreateBindingElements method of your binding:

SecurityBindingElement security = SecurityBindingElement.CreateUserNameOverTransportBindingElement();
collection.Add(security);
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号