title: Is it possible to use ASP.NET MembershipProvider/RoleProvider in self-hosted WCF services?
body: <p>I am trying to use custom ASP.NET MembershipProvider and RoleProvider to handle security for my service. The service is self-hosted in a console app, not in IIS. 
  I use webHttpBinding with Basic Authentication. I configured serviceCredentials and serviceAuthorization to use providers. Providers really get initialized. But WCF seems to ignore my settings and tryes to login user to Windows. I figured that out from Events Log, and proved by sending my windows credentials to the service. Below you can see my configuration and debug screenshots. Why is it using windows for auth? Maybe it is impossible to use ASP.NET auth providers without IIS?</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8" ?&gt;
  &lt;configuration&gt;
  
    &lt;system.web&gt;
      &lt;roleManager
      enabled="true"
      defaultProvider="CustomRoleProvider"&gt;
        &lt;providers&gt;
          &lt;clear/&gt;
          &lt;add
              name="CustomRoleProvider"
              type="CustomRoles.CustomRoleProvider, CustomRoles"/&gt;
        &lt;/providers&gt;
      &lt;/roleManager&gt;
      &lt;membership defaultProvider="CustomMembershipProvider" userIsOnlineTimeWindow="15"&gt;
        &lt;providers&gt;
          &lt;clear/&gt;
          &lt;add name="CustomMembershipProvider"
            type="CustomRoles.CustomMembershipProvider, CustomRoles"/&gt;
        &lt;/providers&gt;
      &lt;/membership&gt;
    &lt;/system.web&gt;
    &lt;system.serviceModel&gt;
      &lt;bindings&gt;
        &lt;webHttpBinding&gt;
          &lt;binding name="webHttp"&gt;
            &lt;security mode="TransportCredentialOnly"&gt;
              &lt;transport clientCredentialType="Basic" /&gt;
            &lt;/security&gt;
          &lt;/binding&gt;
        &lt;/webHttpBinding&gt;
      &lt;/bindings&gt;
      &lt;behaviors&gt;
        &lt;serviceBehaviors&gt;
          &lt;behavior name="Service"&gt;
            &lt;serviceAuthorization principalPermissionMode="UseAspNetRoles"
              roleProviderName="CustomRoleProvider" /&gt;
            &lt;serviceCredentials&gt;
              &lt;userNameAuthentication userNamePasswordValidationMode="MembershipProvider"
                membershipProviderName="CustomMembershipProvider" /&gt;
            &lt;/serviceCredentials&gt;
            &lt;serviceSecurityAudit auditLogLocation="Application" serviceAuthorizationAuditLevel="SuccessOrFailure"
              messageAuthenticationAuditLevel="SuccessOrFailure" /&gt;
          &lt;/behavior&gt;
        &lt;/serviceBehaviors&gt;
      &lt;/behaviors&gt;
      &lt;services&gt;
        &lt;service behaviorConfiguration="Service" name="CustomRoles.Service"&gt;
          &lt;endpoint address="http://127.0.0.1:8060" binding="webHttpBinding"
            bindingConfiguration="webHttp" contract="CustomRoles.IService" /&gt;
        &lt;/service&gt;
      &lt;/services&gt;
    &lt;/system.serviceModel&gt;
  &lt;/configuration&gt;
  </code></pre>
  
  <p>That's what I see when debug. Why is it using windows for auth?</p>
  
  <p><a href="http://img81.imageshack.us/img81/1289/credentials.gif" rel="nofollow noreferrer">credentials screen http://img81.imageshack.us/img81/1289/credentials.gif</a></p>
  
  <p><a href="http://img81.imageshack.us/img81/1289/credentials.gif" rel="nofollow noreferrer">link to full size screen</a></p>