title: WCF - Cannot Find the x.509 Certificate Using the Following Search Criteria
body: <p>Ok, I have seen several questions related to this issue, and I have tried a lot of the ideas presented in them with no success. Here's my situation:</p>
  
  <p>I'm hitting a web service over my company's intranet. I have used svcutil.exe to generate the client class for WCF. I was able to run the web service call with no problem when the service was in development and did not require authentication credentials, so I know the code works. At the time, the code was running over SSL. I imported the required certificate into the Trusted Root Certification Authorities store, and everything was fine.</p>
  
  <p>We just moved to a stage environment, and the service was upgraded to require credentials to connect. I switched my connection to the new endpoint, and added code to authenticate. This is my first time working with wcf, so please bear with me on any obvious mistakes. My problem is that I cannot locate the certificate via code to pass to the service for authentication. I am basing this off of some online code examples I found. </p>
  
  <p>Here is an example of my config generated by svcutil:</p>
  
  <pre><code>&lt;system.serviceModel&gt;
    &lt;bindings&gt;
     &lt;basicHttpBinding&gt;
      &lt;binding 
          name="xxxSOAPBinding" 
          .... (irrelevant config settings)....
       &lt;readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
        maxBytesPerRead="4096" maxNameTableCharCount="16384" /&gt;
       &lt;security mode="Transport"&gt;
        &lt;transport clientCredentialType="Certificate" /&gt;
       &lt;/security&gt;
      &lt;/binding&gt;
     &lt;/basicHttpBinding&gt;
    &lt;/bindings&gt;
    &lt;client&gt;
     &lt;endpoint address="https://xxxServices_1_0_0"
      binding="basicHttpBinding" bindingConfiguration="xxxSOAPBinding" 
      contract="xxxService" name="xxxService" /&gt;
    &lt;/client&gt;
   &lt;/system.serviceModel&gt;
  </code></pre>
  
  <p>And here is the code I am using to try to connect. The exception is thrown as soon as I attempt to locate the certificate:</p>
  
  <pre><code>using (var svc = new xxxServiceClient())
  {
      svc.ClientCredentials.UserName.UserName = "XXX";
      svc.ClientCredentials.UserName.Password = "XXX";
  
      svc.ClientCredentials.ClientCertificate
       .SetCertificate(StoreLocation.LocalMachine, StoreName.Root, 
                       X509FindType.FindBySubjectName, "xxx");
  ...
  }
  </code></pre>
  
  <p>I have tried several different X509FindTypes, and matched them to the values on the cert with no success. Is there something wrong with my code? Is there another way I can query the cert store to validate the values I am passing?</p>
  
  <p>The dev machine where I am running Visual Studio has had the cert imported.</p>