title: IIS hosted WCF with SSL security -"The HTTP request was forbidden with client authentication scheme 'Anonymous'" error
body: <p>I am trying to host wcf on IIS using transport security. I found a good tutorial and follow the instructions : <a href="http://robbincremers.me/2011/12/27/wcf-transport-security-and-client-certificate-authentication-with-self-signed-certificates/" rel="noreferrer">http://robbincremers.me/2011/12/27/wcf-transport-security-and-client-certificate-authentication-with-self-signed-certificates/</a>. I am always getting "The HTTP request was forbidden with client authentication scheme 'Anonymous'". How can I handle it?</p>
  
  <p>What I did so far is:</p>
  
  <ol>
  <li><p>I created self-signed root authority certificate as explained <a href="http://msdn.microsoft.com/tr-tr/library/ms733813(v=vs.110).aspx" rel="noreferrer">here</a>.</p>
  
  <p>makecert -n "CN=TempCA" -r -sv TempCA.pvk TempCA.cer</p></li>
  <li><p>Created a new server certificate signed by a root authority certificate</p>
  
  <p>makecert -sk SignedByCA -iv TempCA.pvk -n "CN=localhost" -ic TempCA.cer localhost.cer -sr localmachine -ss My</p></li>
  <li><p>Created a new client certificate signed by a root authority certificate </p>
  
  <p>makecert -sk SignedByCA -iv TempCA.pvk -n "CN=clientCert" -ic TempCA.cer clientCert.cer -sr localmachine -ss My</p></li>
  <li><p>Added CA to Trusted Root Certificate </p>
  
  <p><img src="https://i.stack.imgur.com/q4Ldu.png" alt="enter image description here"></p></li>
  <li><p>Added these certificates to Personal --> Certificates
  <img src="https://i.stack.imgur.com/vkUBZ.png" alt="enter image description here"></p></li>
  <li><p>Added client certificate to Trusted People
  <img src="https://i.stack.imgur.com/KA7sT.png" alt="enter image description here"></p></li>
  <li><p>Everything looks OK
  <img src="https://i.stack.imgur.com/cglzR.png" alt="enter image description here"></p></li>
  <li><p>Created very simple WCF application. Added it IIS
  <img src="https://i.stack.imgur.com/lhyRK.png" alt="enter image description here"></p></li>
  <li><p>Adjust security settings
  <img src="https://i.stack.imgur.com/HTspM.png" alt="enter image description here"></p></li>
  <li><p>This is my service web.config file</p></li>
  </ol>
  
  <blockquote>
  <pre><code>&gt; &lt;?xml version="1.0"?&gt; &lt;configuration&gt;   &lt;system.web&gt;
  &gt;     &lt;compilation debug="true" targetFramework="4.5" /&gt;
  &gt;     &lt;httpRuntime targetFramework="4.5"/&gt;   &lt;/system.web&gt;   &lt;system.serviceModel&gt;
  &gt;     &lt;bindings&gt;
  &gt;       &lt;basicHttpBinding&gt;
  &gt;         &lt;binding name="EmployeeBindingConfig"&gt;
  &gt;           &lt;security mode="Transport"&gt;
  &gt;             &lt;transport clientCredentialType="Certificate" /&gt;
  &gt;           &lt;/security&gt;
  &gt;         &lt;/binding&gt;
  &gt;       &lt;/basicHttpBinding&gt;
  &gt;     &lt;/bindings&gt;
  &gt;     &lt;behaviors&gt;
  &gt;       &lt;serviceBehaviors&gt;
  &gt;         &lt;behavior name="EmployeeServiceBehavior"&gt;
  &gt;           &lt;serviceMetadata httpsGetEnabled="true"/&gt;
  &gt;           &lt;serviceDebug includeExceptionDetailInFaults="true"/&gt;
  &gt;           &lt;serviceCredentials&gt;
  &gt;             &lt;clientCertificate&gt;
  &gt;               &lt;authentication certificateValidationMode="PeerOrChainTrust"
  &gt; trustedStoreLocation="LocalMachine" /&gt;
  &gt;             &lt;/clientCertificate&gt;
  &gt;           &lt;/serviceCredentials&gt;
  &gt;         &lt;/behavior&gt;
  &gt;       &lt;/serviceBehaviors&gt;
  &gt;     &lt;/behaviors&gt;
  &gt;     &lt;services&gt;
  &gt;       &lt;service
  &gt;         behaviorConfiguration="EmployeeServiceBehavior"
  &gt;         name="WCF.Tutorial.TransportSecurity.ServiceNew.EmployeeService"&gt;
  &gt;         &lt;host&gt;
  &gt;           &lt;baseAddresses&gt;
  &gt;             &lt;add baseAddress="https://localhost/WCF.Tutorial.TransportSecurity.ServiceNew"/&gt;
  &gt;           &lt;/baseAddresses&gt;
  &gt;         &lt;/host&gt;
  &gt;         &lt;endpoint address="EmployeeService"
  &gt;                   binding="basicHttpBinding"
  &gt;                   bindingConfiguration="EmployeeBindingConfig"
  &gt;                   contract="WCF.Tutorial.TransportSecurity.ServiceNew.IEmployeeService"
  &gt; /&gt;
  &gt;         &lt;endpoint
  &gt;            address="mex"
  &gt;            binding="mexHttpsBinding"
  &gt;            contract="IMetadataExchange" /&gt;
  &gt;       &lt;/service&gt;
  &gt;     &lt;/services&gt;   &lt;/system.serviceModel&gt;   &lt;system.webServer&gt;
  &gt;     &lt;modules runAllManagedModulesForAllRequests="true"/&gt;   &lt;/system.webServer&gt; &lt;/configuration&gt;
  </code></pre>
  </blockquote>
  
  <ol start="11">
  <li>This is my client app.config</li>
  </ol>
  
  <blockquote>
  <pre><code>&gt;     &lt;?xml version="1.0" encoding="utf-8" ?&gt;
  &gt;     &lt;configuration&gt;
  &gt;         &lt;startup&gt; 
  &gt;             &lt;supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" /&gt;
  &gt;         &lt;/startup&gt;
  &gt;       &lt;system.serviceModel&gt;
  &gt;         &lt;behaviors&gt;
  &gt;           &lt;endpointBehaviors&gt;
  &gt;             &lt;behavior name="EmployeeEndpointBehaviour"&gt;
  &gt;               &lt;clientCredentials&gt;
  &gt;                 &lt;clientCertificate storeLocation="LocalMachine" storeName="My" x509FindType="FindBySubjectName" findValue="omer-HP"/&gt;
  &gt;               &lt;/clientCredentials&gt;
  &gt;             &lt;/behavior&gt;
  &gt;           &lt;/endpointBehaviors&gt;
  &gt;         &lt;/behaviors&gt;
  &gt;         &lt;bindings&gt;
  &gt;           &lt;basicHttpBinding&gt;
  &gt;             &lt;binding name="EmployeeBindingConfig"&gt;
  &gt;               &lt;security mode="Transport"&gt;
  &gt;                 &lt;transport clientCredentialType="Certificate" /&gt;
  &gt;               &lt;/security&gt;
  &gt;             &lt;/binding&gt;
  &gt;           &lt;/basicHttpBinding&gt;
  &gt;         &lt;/bindings&gt;
  &gt;         &lt;client&gt;
  &gt;           &lt;endpoint address="https://localhost/WCF.Tutorial.TransportSecurity.ServiceNew/EmployeeService.svc"
  &gt;                     binding="basicHttpBinding" bindingConfiguration="EmployeeBindingConfig"
  &gt;             contract="WCF.Tutorial.TransportSecurity.ServiceNew.IEmployeeService"
  &gt; name="serviceEndpoint"
  &gt; behaviorConfiguration="EmployeeEndpointBehaviour"/&gt;
  &gt;         &lt;/client&gt;
  &gt;       &lt;/system.serviceModel&gt;
  &gt;     &lt;/configuration&gt;
  </code></pre>
  </blockquote>
  
  <ol start="12">
  <li>This is my client code and error
  <img src="https://i.stack.imgur.com/B8PIg.png" alt="enter image description here"></li>
  </ol>
  
  <p>My question is how can I pass this error? I need your help.</p>