WCF REST cliente de autenticación de Windows

Estoy siguiendo el siguiente ejemplo, pero obtengo un error 401 no autorizado en el lado del servidor.

https: //www.dotnetcurry.com/ShowArticle.aspx? ID = 434

Intenté a continuaciónWCF REST Service con Windows Authenticati, on y SSL

WCF Problema de autenticación de Windows con el servicio REST

Esto está cerca del mío

Cómo consumir el servicio de descanso wcf con autenticación de Windows

Tengo una interfaz IService como la siguiente

[OperationContract]
[WebInvoke(
    Method = "POST",
    UriTemplate = "/Students/getStudents",
    BodyStyle = WebMessageBodyStyle.Bare,
    RequestFormat = WebMessageFormat.Json,
    ResponseFormat = WebMessageFormat.Json)]
 void GetAllStudents();

En el servicio de Windows app.config que actúa como host para mi servicio de descanso WCF que tengo a continuación

<system.serviceModel>
<bindings>
<webHttpBinding>
   <binding name="webHttpBindingConfiguration" maxBufferSize="2147483647" maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647">
    <readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647"
                  maxArrayLength="2147483647" maxBytesPerRead="2147483647"
                  maxNameTableCharCount="2147483647" />
       <security mode="TransportCredentialOnly">
          <transport clientCredentialType="Windows" proxyCredentialType="Windows" />
        </security>
    </binding>
</webHttpBinding>
</bindings>
<behaviors>
      <serviceBehaviors>
         <behavior name="WCFRESTServiceBehavior">         
          <serviceMetadata httpGetEnabled="True" httpGetUrl="http://localhost:2023/MyRESTService"/>
          <serviceDebug includeExceptionDetailInFaults="False" />
          <serviceCredentials>
            <windowsAuthentication allowAnonymousLogons="false" includeWindowsGroups="true"/>
          </serviceCredentials>
        </behavior>
      </serviceBehaviors>         
       <endpointBehaviors>
        <behavior name="webBehaviorConfiguration">
          <webHttp />
        </behavior>
      </endpointBehaviors>        
</behaviors>   
<services>
<service behaviorConfiguration="WCFRESTServiceBehavior"
        name="MYRESTService">
        <endpoint address="http://localhost:2023/MyRESTService"
          behaviorConfiguration="webBehaviorConfiguration" binding="webHttpBinding"
          bindingConfiguration="webHttpBindingConfiguration" contract="IMyRESTService" />
      </service>
</services>
</system.serviceModel>

Estoy haciendo una llamada del cliente como a continuación

url = "http://localhost:2023/MyRESTService/Students/getStudents";
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
request.Method = "POST";
request.ContentType = "application/json";
request.PreAuthenticate = true;
NetworkCredential credential = new NetworkCredential(@"domainname\username", "password");
request.Credentials = credential;

WebResponse response = request.GetResponse();

Consiguiendo Error 401 no autorizado en la solicitud. GetResponse ()

ACTUALIZAR Si doy como a continuación, está funcionando, pero estoy seguro de que está mal, ya que la autenticación no aparecerá. Probé con un nombre de usuario incorrecto y aún funciona, pero esperaba un error no autorizado.

<system.web>
    <authentication mode="None"/>
  </system.web>

<webHttpBinding>
        <binding name="webHttpBindingConfiguration" maxBufferSize="2147483647" maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647">
          <readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647"
                        maxArrayLength="2147483647" maxBytesPerRead="2147483647"
                        maxNameTableCharCount="2147483647" />
          <security mode="None">
            <transport clientCredentialType="Windows" proxyCredentialType="None" realm="" />
          </security>
        </binding>
      </webHttpBinding>
    </bindings>

Respuestas a la pregunta(0)

Su respuesta a la pregunta