Thursday 18 September 2014

Configuring WCF services with Windows Authentication

When you set up a WCF service to use Windows Authentication mode you might get such error message: 401 - Unauthorized: Access is denied due to invalid credentials.
I want to present a solution that works for me.


Editing web.config

First thing is a properly edited web.config file:

Just replace 'service - name' and 'endpoint - contract' attributes values (lines 26, 29) with your specific names.


Configuring service on IIS

Next step is to set Windows Authentication for service in IIS settings. On IIS7 it can be done in following way:
  1. Go to: WebSite - Your service - Authentication:
  2. Disable Anonumous and all others
  3. Enable Windows Authentication
  4. Next click on Windows Authentication and then Providers
  5. Add Negotiate provider
  6. An important thing is providers order
    • NTLM
    • Negotiate


Applying authentication in an application

At your client application add following code so it can authenticate:



    No comments:

    Post a Comment