Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>It is possible. We do something similar with Mutual Certificate Auth - the service certificate and in some cases the client certificate are picked up from a central authority as part of an auto-discovery/single-sign-on mechanism.</p> <p>It's not entirely clear in what context the certificate will be used, but in all cases what you need to do is define your own behavior and behavior element deriving from the particular behavior/element in the <code>System.ServiceModel.Description</code> namespace that takes the certificate. I'll assume for the time being that it's a client credential. First you have to write the behaviour, which goes something like this:</p> <pre><code>public class MyCredentials : ClientCredentials { public override void ApplyClientBehavior(ServiceEndpoint endpoint, ClientRuntime behavior) { // Assuming GetCertificateFromNetwork retrieves from CDS ClientCertificate.Certificate = GetCertificateFromNetwork(); } protected override ClientCredentials CloneCore() { // ... } } </code></pre> <p>Now you need to create an element that can go in the XML configuration:</p> <pre><code>public class MyCredentialsExtensionElement : ClientCredentialsElement { protected override object CreateBehavior() { return new MyCredentials(); } public override Type BehaviorType { get { return typeof(MyCredentials); } } // Snip other overrides like Properties } </code></pre> <p>After this you can add the policy to your WCF config:</p> <pre><code>&lt;behaviors&gt; &lt;endpointBehaviors&gt; &lt;behavior name="MyEndpointBehavior"&gt; &lt;myCredentials/&gt; &lt;/behavior&gt; &lt;/endpointBehaviors&gt; &lt;/behaviors&gt; </code></pre> <p>Edit: Almost forgot to mention, you need to register the extension:</p> <pre><code>&lt;system.serviceModel&gt; &lt;extensions&gt; &lt;behaviorExtensions&gt; &lt;add name="myCredentials" type="MyAssembly.MyCredentialsExtensionElement, MyAssembly, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" /&gt; &lt;/behaviorExtensions&gt; &lt;/extensions&gt; &lt;/system.serviceModel&gt; </code></pre> <p>Hope that helps. If you need more details on the arrangement of all of these classes and what's going on behind the scenes, try reading <a href="http://msdn.microsoft.com/en-us/magazine/cc163302.aspx" rel="noreferrer">Extending WCF with Custom Behaviors</a>.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload