title: WCF https with only server certificate
body: <p>I trying to do WCF using self-signed certificate. I found some solutions,but they need client to know clinet certificate before connection.
  I would like make client works as browser(When browser use web server certificate).
  I mean browser don't know webserver's certificate before connection, it can obtain it from web server. 
  My server's web.config:</p>
  
  <pre><code>&lt;system.serviceModel&gt;
      &lt;serviceHostingEnvironment aspNetCompatibilityEnabled="false" /&gt;
      &lt;services&gt;
        &lt;service behaviorConfiguration="security" name="WebApplicationExchange.UKService"&gt;
          &lt;endpoint address="" binding="basicHttpBinding" bindingConfiguration="security" contract="WebApplicationExchange.IUKService"&gt;
            &lt;identity&gt;
              &lt;dns value="localhost" /&gt;
            &lt;/identity&gt;
          &lt;/endpoint&gt;
          &lt;endpoint address="mex" binding="mexHttpsBinding" contract="IMetadataExchange" /&gt;
          &lt;host&gt;
            &lt;baseAddresses&gt;
              &lt;add baseAddress="https://localhost/UKService/UKService.svc" /&gt;
            &lt;/baseAddresses&gt;
          &lt;/host&gt;
        &lt;/service&gt;
      &lt;/services&gt;
      &lt;behaviors&gt;
        &lt;serviceBehaviors&gt;
          &lt;behavior name="security"&gt;
            &lt;serviceMetadata httpGetEnabled="false" httpsGetEnabled="true" /&gt;
            &lt;serviceCredentials&gt;
              &lt;userNameAuthentication userNamePasswordValidationMode="Custom" customUserNamePasswordValidatorType="ServiceAuthorization.PasswordValidator,ServiceAuthorization" /&gt;
              &lt;windowsAuthentication allowAnonymousLogons="false" /&gt;
            &lt;/serviceCredentials&gt;
            &lt;serviceAuthorization principalPermissionMode="Custom"&gt;
              &lt;authorizationPolicies&gt;
                &lt;add policyType="ServiceAuthorization.AuthorizationPolicy,ServiceAuthorization" /&gt;
              &lt;/authorizationPolicies&gt;
            &lt;/serviceAuthorization&gt;
            &lt;serviceDebug includeExceptionDetailInFaults="true" /&gt;
          &lt;/behavior&gt;
        &lt;/serviceBehaviors&gt;
      &lt;/behaviors&gt;
      &lt;bindings&gt;
        &lt;basicHttpBinding&gt;
          &lt;binding name="security"&gt;
            &lt;security mode="TransportWithMessageCredential"&gt;
              &lt;transport clientCredentialType="Basic" /&gt;
            &lt;/security&gt;
          &lt;/binding&gt;
        &lt;/basicHttpBinding&gt;
      &lt;/bindings&gt;
    &lt;/system.serviceModel&gt;
  </code></pre>
  
  <p>It works fine with web browsers.</p>
  
  <p>But client show error:
  Could not establish trust connection for secure channel SSL / TLS with authority "localhost: 56389".
  Client code:</p>
  
  <pre><code>System.ServiceModel.EndpointAddress eaSecurity = new System.ServiceModel.EndpointAddress("https://localhost:56389/UKService.svc");
                  var binding = new System.ServiceModel.BasicHttpBinding();
                  binding.Security.Mode = System.ServiceModel.BasicHttpSecurityMode.TransportWithMessageCredential;
                  binding.Security.Transport.ClientCredentialType = System.ServiceModel.HttpClientCredentialType.None;
                  binding.Security.Message.ClientCredentialType = System.ServiceModel.BasicHttpMessageCredentialType.UserName;
  
  
                  var securityFactory = new System.ServiceModel.ChannelFactory&lt;ServiceReference1.IUKService&gt;(binding, eaSecurity);
                  securityFactory.Credentials.UserName.UserName = "test";
                  securityFactory.Credentials.UserName.Password = "test";
                  myService = securityFactory.CreateChannel();
  </code></pre>
  
  <p>Any ideas how to solve this?</p>
  
  <p><strong>UPDATE:</strong>
  I look deeper in error stack and find following:
  System.Security.Authentication.AuthenticationException: The remote certificate is invalid according to the results of authentication.
  I tryed this code:</p>
  
  <pre><code>  ClientCredentials cc = securityFactory.Endpoint.Behaviors.Find&lt;ClientCredentials&gt;();
  
                  cc.UserName.UserName = "test";
                  cc.UserName.Password = "test";
  
                 cc.ServiceCertificate.Authentication.CertificateValidationMode = X509CertificateValidationMode.None;
  </code></pre>
  
  <p>But it doesn't help.</p>