0

I have a WCF service hosted in IIS. Authentication mode is set to Windows in web.config and IIS level.

I have a user interface from which the service gets called from jQuery ajax method.

Here is how I am calling service from jQuery.

$.ajax({
            async: true,
            type: "POST",
            contentType: "application/json; charset=utf-8",
            crossDomain: true,
            xhrFields: {
                withCredentials: true
            },
            data: <<Data>>,
            url: <<Service url>>,
            success: function (data) {
                OnFetchSuccess(<<Some Params>>);
            },
            error: function () { }
        });

This call fails with error code 401 (Unauthorized).

Can someone please help in this issue?

VJOY
  • 3,752
  • 12
  • 57
  • 90
  • 1
    try with xhrFields: { withCredentials: true }, in your ajax call . If its doesn't work then you may need to add authorization headers in your request – Arunprasanth K V Oct 11 '17 at 05:15
  • 2
    Possible duplicate of [Got a "401 - Unauthorized" when trying my WCF Data service on IIS](https://stackoverflow.com/questions/7103079/got-a-401-unauthorized-when-trying-my-wcf-data-service-on-iis) – Vijunav Vastivch Oct 11 '17 at 05:17
  • same as here: https://stackoverflow.com/questions/2205038/401-unauthorized-error-wcf-security-binding – Vijunav Vastivch Oct 11 '17 at 05:18
  • Above 2 threads are calling service from code behind. I am facing issue when it is called from jQuery. From c# it works. – VJOY Oct 11 '17 at 10:13

0 Answers0