C# – The authentication schemes configured on the host (‘Basic’) do not allow those configured on the binding ‘BasicHttpBinding’

asp.netcwcf

Error

The authentication schemes configured on the host ('Basic') do not
allow those configured on the binding 'BasicHttpBinding'
('Anonymous'). Please ensure that the SecurityMode is set to
Transport or TransportCredentialOnly. Additionally, this may be
resolved by changing the authentication schemes for this application
through the IIS management tool, through the
ServiceHost.Authentication.AuthenticationSchemes property, in the
application configuration file at the
element, by updating the ClientCredentialType property on the binding,
or by adjusting the AuthenticationScheme property on the
HttpTransportBindingElement.

Do you know where is problem in web.config? I try log into WCF via basic authentication using windows credentials.

<?xml version="1.0"?>
<configuration>
  <system.web>
    <compilation debug="true" targetFramework="4.0" />
    <authentication mode="Windows" />
    <customErrors mode="Off"/>
  </system.web>
  <system.serviceModel>
    <behaviors>
      <serviceBehaviors>
        <behavior>
          <!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment -->
          <serviceMetadata httpGetEnabled="true"/>
          <!-- To receive exception details in faults for debugging purposes, set the value below to true.  Set to false before deployment to avoid disclosing exception information -->
          <serviceDebug includeExceptionDetailInFaults="false"/>
        </behavior>
      </serviceBehaviors>
    </behaviors>
    <serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
    <bindings>
      <basicHttpBinding>
        <binding name="basicEndpoint">
          <security mode="Transport" >
            <transport clientCredentialType="Basic"
                       proxyCredentialType="None"
                       realm="" />
          </security>
        </binding>
      </basicHttpBinding>
    </bindings>
  </system.serviceModel>
  <system.webServer>
    <modules runAllManagedModulesForAllRequests="true">
      <add name="BasicAuthHttpModule"
        type="Wt.BasicAuthHttpModule, Wt"/>
    </modules>
  </system.webServer>

</configuration>

enter image description here

Best Answer

It seems you are using the Simplified Configuration for WCF Services.

If you do not explicitly specify your endpoint service and its bindingConfiguration, WCF would do the following:

  • It will associate the default binding to the protocol used (scheme).
  • It will load the default bindingConfiguration of the binding type.

For the protocol mapping see this explanation Simplified Configuration

The default bindingConfiguration does not have a name, so if you give a specific name to your basicHttpBinding configuration you are not overwriting the default binding configuration. It should be instead

<basicHttpBinding>
    <binding>
        <security mode="Transport">
            <transport clientCredentialType="Basic"
                proxyCredentialType="None"
                realm="" />
        </security>
    </binding>
</basicHttpBinding>