Search code examples
angularjswcfrest

Calling WCF from angularjs GET works, POST not


I'm calling a wcf-service hosted on iis from my angularjs-application (same machine). Whe nmaking a GET-call on a function I'm getting back results but when making a POST the call doesn't get through. Instead I'm getting a 401.2 Unauthorized. I'm using HTTPS and in IIS Windows Auth is enabled and Anonymous is disabled

The call works when using the advanced Rest client (chrome plugin).

Fiddler shows the following headers: Request:

https://serviceurl/service.svc/rest/SetDailyDetails HTTP/1.1
Host: serviceurl
Connection: keep-alive
Access-Control-Request-Method: POST
Origin: https://localhost:44305
User-Agent: Mozilla/5.0 (Windows NT 6.2; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/37.0.2062.120 Safari/537.36
Access-Control-Request-Headers: accept, content-type
Accept: */*
Referer: https://localhost:44305/Pages/PresenceDetail.aspx?SPHostUrl=https%3A%2F%2Fserviceurl&SPLanguage=en-US&SPClientTag=4&SPProductNumber=15%2E0%2E4505%2E1005
Accept-Encoding: gzip,deflate
Accept-Language: de-DE,de;q=0.8,en-US;q=0.6,en;q=0.4

Response:

https://serviceurl.svc/rest/SetDailyDetails HTTP/1.1
Host: serviceurl
Connection: keep-alive
Access-Control-Request-Method: POST
Origin: https://localhost:44305
User-Agent: Mozilla/5.0 (Windows NT 6.2; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/37.0.2062.120 Safari/537.36
Access-Control-Request-Headers: accept, content-type
Accept: */*
Referer: https://localhost:44305/Pages/PresenceDetail.aspx?SPHostUrl=https%3A%2F%2Fserviceurl&SPLanguage=en-US&SPClientTag=4&SPProductNumber=15%2E0%2E4505%2E1005
Accept-Encoding: gzip,deflate
Accept-Language: de-DE,de;q=0.8,en-US;q=0.6,en;q=0.4

My Wcf-configuration:

  <customHeaders>
    <add name="Access-Control-Allow-Origin" value="https://localhost:44305" />
    <add name="Access-Control-Allow-Credentials" value="true" />
    <add name="Access-Control-Allow-Headers" value="Authorization, Origin, Content-Type, Accept, X-Requested-With" />
    <add name="Access-Control-Allow-Methods" value="POST,GET,OPTIONS" />
    <add name="Access-Control-Max-Age" value="1728000" />
  </customHeaders>

Can someone help?


Solution

  • This was a CORS-Problem. We solved it by Setting the OPTIONS-Handler in IIS at the top for the wcf-service site.