I am writing WCF services that will be used by clients in the wild, so they must handle cross-origin requests. I had a problem submitting such development requests to my development server. Here is the scenario:
- I am running a WCF project on an instance of Visual Studio 2012 using IIS Express 8 as a server on a specific port.
- I am running a client project on another instance of Visual Studio 2012, also using IIS Express 8 as the server. This project uses AJAX to consume services in another project.
When I run the client project in IE, there is no problem because IE does not send the OPF preflight request. When I run it in Chrome, however, requesting OPTIONS options returns 405 Method Not Allowed, and Chrome refuses this service. Previous versions of Chrome would simply ignore the error and continue with the actual POST request (or Get, regardless ...), but later versions look pickier.
I also came across this with a deployed WCF project and solved it by moving OPTIONSVerbHandler to the top of the list of handler mappings in IIS.
I must indicate that I am using the most generous web.config settings that I can come up with to try to enable CORS. For example, I have this in the WCF project configuration:
<httpProtocol> <customHeaders> <remove name="X-Powered-By" /> <add name="Access-Control-Allow-Origin" value="*" /> <add name="Access-Control-Allow-Headers" value="*" /> <add name="Access-Control-Allow-Methods" value="*" /> <add name="X-Powered-By" value="*" /> </customHeaders> </httpProtocol>
Regardless of the fact that any client cross-start requests for a WCF project launched from code do not work with error 405.
Any help setting up the WCF or IIS Express 8 project itself to enable CORS?
Thanks!
source share