WCF/WF - WCF Windows Authentication

Asked By Raghu Donk on 29-Apr-10 11:12 AM
Hi I am enabling windows authentication on one of my server in IIS 7, I wrote a client code to send request to that service and I am getting this error

The HTTP request is unauthorized with client authentication scheme 'Ntlm'. The authentication header received from the server was 'Negotiate,NTLM'.

I have to use NTLM authentication and I have configured NTLM on Web.config and app.config on server and client side, and I am sending a serviceaccount from my client code to invoke the service. what should I do to enable windows authentication for my WCF service.

Thanks
Peter Bromberg replied to Raghu Donk on 29-Apr-10 03:58 PM

In the web.config for the service, in the Transport element, set the ClientCredentialType to Windows: 

<bindings>
      <basicHttpBinding>
          <binding name="MyBinding">
              <security mode="TransportCredentialOnly">
                  <transport clientCredentialType="Windows" />
              </security>
          </binding>
      </basicHttpBinding>
  </bindings>

In your web.config, set the allowed roles and or users:

<system.web>
            <authentication mode="Windows"/>
            <authorization>
                  <allow roles=".\Developers"/>
                  <allow users="DOMAIN\ServiceAccount"/>
                  <deny users="*"/>
            </authorization>
      </system.web>

In IIS,  your virtual application hosting your WCF service will need to be configured to use Windows Integrated authentication. Be sure to uncheck Anonymous Access.

On the client side, svcutil (or using "Add Service Reference")  will generate the corresponding client elements to match that of your service.  If using a Windows client, the credentials of the actual user will be passed downstream.