title: The HTTP request was forbidden with client authentication scheme 'Anonymous'. The remote server returned an error: (403) Forbidden
body: <p>I am trying to create a secure webservice. </p>
  
  <p>Here is the contract and service implementation</p>
  
  <pre><code>[ServiceContract()]
  public interface ICalculatorService
  {
      [OperationContract()]
      int Add(int x, int y);
  }
  
  [ServiceBehavior(IncludeExceptionDetailInFaults=true)]
  public class CalculatorService : ICalculatorService
  {
      public int Add(int x, int y)
      {
          return x + y;
      }
  }
  </code></pre>
  
  <p>Here i have the service code</p>
  
  <pre><code>var b = new WSHttpBinding(SecurityMode.Transport);
  b.Security.Transport.ClientCredentialType = HttpClientCredentialType.Certificate;
  b.Security.Message.ClientCredentialType = MessageCredentialType.None;
  
  Type contractType = typeof(ICalculatorService);
  Type implementedContract = typeof(CalculatorService);
  Uri baseAddress = new Uri("https://localhost:8006/CalculatorService");
  ServiceHost sh = new ServiceHost(implementedContract);
  
  sh.AddServiceEndpoint(contractType, b, baseAddress);
  
  //ServiceMetadataBehavior sm = new ServiceMetadataBehavior();
  //sm.HttpsGetEnabled = true;
  //sm.HttpsGetUrl = new Uri("https://localhost:8006/CalculatorServiceMex");
  //sh.Description.Behaviors.Add(sm);
  
  sh.Credentials.Peer.PeerAuthentication.CertificateValidationMode = System.ServiceModel.Security.X509CertificateValidationMode.PeerTrust;
          sh.Credentials.ServiceCertificate.SetCertificate(StoreLocation.LocalMachine, StoreName.TrustedPeople, X509FindType.FindBySubjectName, "localhost");
  
  sh.Open();
  Console.WriteLine("Service is Listening");
  Console.ReadLine();
  sh.Close();
  </code></pre>
  
  <p>Here is the client code</p>
  
  <pre><code>var b = new WSHttpBinding(SecurityMode.Transport);
  b.Security.Transport.ClientCredentialType = HttpClientCredentialType.Certificate;
  b.Security.Message.ClientCredentialType = MessageCredentialType.None;
  
  var factory = new ChannelFactory&lt;ICalculatorService&gt;(b);
  factory.Credentials.Peer.PeerAuthentication.CertificateValidationMode = System.ServiceModel.Security.X509CertificateValidationMode.PeerTrust;
          factory.Credentials.ClientCertificate.SetCertificate(StoreLocation.LocalMachine, StoreName.TrustedPeople, X509FindType.FindBySubjectName, "localhost");
  
  var client = factory.CreateChannel(new EndpointAddress(new Uri("https://localhost:8006/CalculatorService")));
  
  ServicePointManager.ServerCertificateValidationCallback =
     ((sender, certificate, chain, sslPolicyErrors) =&gt;
              {
                  return true;
              });
  
  ICommunicationObject comObject = client as ICommunicationObject;
  int result = -1;
  try
  {
    comObject.Open();
    result = client.Add(10, 2);
  }
  catch (Exception ex)
  {
  
  }
  Console.WriteLine(string.Format("Service say 10 + 2 = {0}", -1));
  Console.ReadLine();
  </code></pre>
  
  <p>The service runs fine and when the ServicePointManager.ServerCertificateValidationCallback check is made there are no policy errors, with the correct certificate chain built. </p>
  
  <p><img src="https://i.stack.imgur.com/CJpux.png" alt="enter image description here"></p>
  
  <p>I have my CA in the trusted root and the server/client cert in the TrustedPeople store. Also if I navigate to the site from a browser I see a page returned. No errors<img src="https://i.stack.imgur.com/p7ahm.png" alt="enter image description here"></p>
  
  <p>I have updated IIS to what I think are the required, bound the certificate in in IIS
  <img src="https://i.stack.imgur.com/EBGgO.png" alt="enter image description here"></p>
  
  <p>and via command line below.
  <img src="https://i.stack.imgur.com/L84iE.png" alt="enter image description here"></p>
  
  <p>I've set the SSL settings to accept certificates
  <img src="https://i.stack.imgur.com/T18Hd.png" alt="enter image description here"></p>
  
  <p>and enabled anonymous authentication.
  <img src="https://i.stack.imgur.com/aGeqD.png" alt="enter image description here"></p>
  
  <p>Does anyone know what steps I've not done correctly or see anything amiss? I keep getting the same error <strong>"The HTTP request was forbidden with client authentication scheme 'Anonymous'."</strong></p>