Wednesday, 30 January 2013

Calling WCF REST Service from Jquery causes 405 method Not Allowed and Authorization

I was investigating how to call a REST web service using an Authorization header from jQuery but was running into a cross domain issue. I found the following blog post which detailed changes to the Global.asax :-

After a bit of head scratching, I found that the above solution required an addition to support an Authorization header.

So from the above blog post, the following line :-

HttpContext.Current.Response.AddHeader("Access-Control-Allow-Headers", "Content-Type, Accept");

Needed to read :-

HttpContext.Current.Response.AddHeader("Access-Control-Allow-Headers", "Content-Type, Accept, Authorization");