title: WCF REST Service with Windows Authentication and SSL
body: <p>I have WCF Rest Service that is being consumed by android, iOS and asp.net web application. all endpoint methods return json format so I use webHttpBinding. Problems started when I secured the service by activating Windows authentication(disabled Anonymous before that). When I try to add Service reference from the asp.net web application I receive the following error: </p>
  
  <pre><code>The HTTP request is unauthorized with client authentication scheme 'Anonymous'. The authentication header received from the server was 'Negotiate,NTLM'.
  The remote server returned an error: (401) Unauthorized.
  </code></pre>
  
  <p>When I call endpoints in browser windows dialog is being showed with username and pass and everything works fine, but When I try to add the reference I receive the error. I'm also using SSL and the service has only https address.</p>
  
  <p><strong>web.config wcf rest service:</strong></p>
  
  <pre><code>&lt;system.web&gt;
  &lt;compilation debug="true" targetFramework="4.5" /&gt;
  &lt;httpRuntime targetFramework="4.5" executionTimeout="90"        maxRequestLength="20000" useFullyQualifiedRedirectUrl="false" requestLengthDiskThreshold="8192" /&gt;
      &lt;authentication mode="Windows" /&gt;
  &lt;/system.web&gt;
  &lt;system.serviceModel&gt;
  &lt;serviceHostingEnvironment aspNetCompatibilityEnabled="true" /&gt;
  &lt;bindings&gt;
    &lt;webHttpBinding&gt;
      &lt;binding name="WebHttpEndpointBinding"   maxReceivedMessageSize="200000000" maxBufferPoolSize="200000000"&gt;
        &lt;readerQuotas maxDepth="32" maxArrayLength="2000000000"   maxStringContentLength="2000000000" /&gt;
        &lt;security mode="Transport"&gt;
        &lt;transport clientCredentialType="Windows"  /&gt; 
        &lt;/security&gt;
      &lt;/binding&gt;
    &lt;/webHttpBinding&gt;  
  &lt;/bindings&gt;
  &lt;services&gt;
    &lt;service name="restSrvService.restSrvRestService"   behaviorConfiguration="serviceBehavior"&gt;
      &lt;endpoint address="" name="webHttpEndpoint" binding="webHttpBinding"   bindingConfiguration="WebHttpEndpointBinding" behaviorConfiguration="web"   contract="restSrvService.IrestSrvRestService"&gt;   
      &lt;/endpoint&gt; 
   &lt;endpoint address="mex" binding="mexHttpBinding"  contract="IMetadataExchange"/&gt;
    &lt;/service&gt;
  &lt;/services&gt;
  &lt;behaviors&gt;
    &lt;serviceBehaviors&gt;
      &lt;behavior name="serviceBehavior"&gt;
        &lt;serviceMetadata httpGetEnabled="true" httpsGetEnabled="true" /&gt;
       &lt;serviceAuthenticationManager authenticationSchemes="IntegratedWindowsAuthentication" /&gt;
        &lt;serviceDebug includeExceptionDetailInFaults="true" /&gt;
      &lt;/behavior&gt;
    &lt;/serviceBehaviors&gt;
    &lt;endpointBehaviors&gt;
      &lt;behavior name="web"&gt;
        &lt;endpointDiscovery enabled="true"&gt;
        &lt;/endpointDiscovery&gt;
        &lt;webHttp  /&gt;
      &lt;/behavior&gt;
    &lt;/endpointBehaviors&gt;
  &lt;/behaviors&gt;
  &lt;/system.serviceModel&gt;
  </code></pre>
  
  <p><strong>web.config web application:</strong> </p>
  
  <pre><code>    &lt;system.webServer&gt;
        &lt;modules runAllManagedModulesForAllRequests="true"&gt;&lt;/modules&gt;
      &lt;/system.webServer&gt;
      &lt;system.serviceModel&gt;
      &lt;bindings&gt;
       &lt;webHttpBinding&gt;
         &lt;binding name="WebHttpEndpointBinding" bypassProxyOnLocal="true" useDefaultWebProxy="true" maxReceivedMessageSize="200000000" maxBufferPoolSize="200000000"&gt;
           &lt;readerQuotas maxDepth="32" maxArrayLength="2000000000" maxStringContentLength="2000000000" /&gt;
             &lt;security mode="Transport"&gt;
               &lt;transport clientCredentialType="Windows"&gt;&lt;/transport&gt;
             &lt;/security&gt;
         &lt;/binding&gt;
       &lt;/webHttpBinding&gt;
      &lt;/bindings&gt;
      &lt;client&gt;
  
        &lt;endpoint address="https://serviceAddress/restSrvRestService.svc/"
          binding="webHttpBinding" bindingConfiguration="WebHttpEndpointBinding"
          contract="restSrvService.IrestSrvRestService"  behaviorConfiguration="webEndpoint" name="WebHttpEndpoint"&gt;
          &lt;identity&gt;
          &lt;/identity&gt;
        &lt;/endpoint&gt;
      &lt;/client&gt;
      &lt;behaviors&gt;
        &lt;endpointBehaviors&gt;
          &lt;behavior name="webEndpoint"&gt;
            &lt;webHttp /&gt;
          &lt;/behavior&gt;
        &lt;/endpointBehaviors&gt;
      &lt;/behaviors&gt;
    &lt;/system.serviceModel&gt;
  </code></pre>