how to avoid cross domain policy in jquery ajax for consuming wcf service??
What chages do i need to do in web.config for cross domain policy?
how to avoid cross domain policy in jquery ajax for consuming wcf service??
What chages do i need to do in web.config for cross domain policy?
If you want cross domain calls from javascript to WCF you must use JSONP. To add JSONP support to WCF you must define it in
WebHttpBinding
. The configuration should look like:For jQuery part check for example this article.
chrome/firefox wouldn't let me do this until i explicitly set
in my calls
I got it to work using the JQuery (1.5.1) $.ajax CrossDomain setting set to true.
What I don't understand yet is why it is that when using the attribute [ScriptMethod(ResponseFormat = ResponseFormat.Json)] on the WCF (.NET4) service, the call succeeds without the crossdomain setting (to web.config and $.ajax) and when using the attribute [WebGet(ResponseFormat = WebMessageFormat.Json)] it requires the crossdomain settings in webconfig and $.ajax call. If I use WebGet attribute without the crossdomain settings I'll get an "Method Not Allowed" error.
WCF code is used:
any ideas?