title: WCF certificates not being set on custom credentials
body: <p>I have a custom implementation of ClientCredentials in WCF. Two of the base properties of ClientCredentials are the ClientCertificate and ServiceCertificate, as seen <a href="http://msdn.microsoft.com/en-us/library/system.servicemodel.description.clientcredentials_properties.aspx" rel="nofollow noreferrer">here (MSDN)</a>.</p>
  
  <p>In my configuration, I have my custom ClientCredentials set, and both certificates defined:</p>
  
  <pre><code>        &lt;endpointBehaviors&gt;
              &lt;behavior name="MyCustomEndpointBehavior"&gt;
                  &lt;clientCredentials type="MyApp.Security.CentralAuthClientCredentials, MyApp"&gt;
                      &lt;clientCertificate findValue="localhost" x509FindType="FindBySubjectName" storeLocation="CurrentUser" storeName="My" /&gt;
                      &lt;serviceCertificate&gt;
                          &lt;defaultCertificate findValue="localhost" x509FindType="FindBySubjectName" storeLocation="CurrentUser" storeName="My" /&gt;
                          &lt;authentication certificateValidationMode="None" revocationMode="NoCheck" /&gt;
                      &lt;/serviceCertificate&gt;
                  &lt;/clientCredentials&gt;
              &lt;/behavior&gt;
          &lt;/endpointBehaviors&gt;
  </code></pre>
  
  <p>This configuration was <em>completely 100%</em> working with UserName authentication. It used the certs to encrypt the username and password for the Message. Then I changed to my custom ClientCredentials.</p>
  
  <p>At runtime, here are the properties that are set on my CentralAuthClientCredentials:</p>
  
  <pre><code>this.ClientCertificate = System.ServiceModel.Security.X509CertificateInitiatorClientCredential
  this.ClientCertificate.Certificate = null
  this.ServiceCertificate = System.ServiceModel.Security.X509CertificateRecipientClientCredential
  this.ServiceCertificate.DefaultCertificate = null
  </code></pre>
  
  <p>So, why are the client and service default certificate that are defined in configuration <em>not</em> set on the actual instantiated object? It looks as if WCF ignored the XML tags completely!</p>
  
  <p>Is there some code I can use, maybe in the constructor of the credentials, to get those certificates from the configuration manually?</p>
  
  <p>Thanks for any help!</p>
  
  <hr>
  
  <p><strong>Update</strong></p>
  
  <p>I'm an idiot. I figured it out. WCF was actually creating my instance correctly with the certificates set, but in my wcf client, I had the following remove/add series, that I <em>think</em> I copied from the MSDN example:</p>
  
  <pre><code>this.ChannelFactory.Endpoint.Behaviors.Remove&lt;ClientCredentials&gt;();
  this.ChannelFactory.Endpoint.Behaviors.Add(new CentralAuthClientCredentials());
  return base.Channel.MyServiceMethod();
  </code></pre>
  
  <p>To remove the old credentials and add my own custom ones.  However this was making a new instance that didnt have the certificates set! oops!</p>