Accessing Cross-Domain WCF-Webservice with jQuery or Javascript -


i'm sorry ask question again, didn't find fitting answer problem.

i try build following: want connect wcf-webservice standard webpage. both website , web service hosted in iis on same machine.

i enabled cross-domain web.config:

<webhttpbinding>     <binding name="webhttpbindingwithjsonp" crossdomainscriptaccessenabled="true" /> </webhttpbinding> 

and ajax request:

$.ajax({     type: "post",     url: config.endpoints.db.production + "adddata/",     data: json.stringify(data),     contenttype: "application/json",     datatype: "json",     crossdomain: true,     //  processdata: true,     success: function(data, status, jqxhr) {         //  alert("success..." + data);         // loadingvisible(false);         //  loadingfinished = true;       },     error: function(xhr) {         alert("failure..." + xhr.responsetext);         //    loadingfinished = true;         //    loadingvisible(false);      } }); 

after firing request got "access denied"-error in visual studio jquery. after searching in web found out common cross-domain problem, didn't find solution. tried set "crossdomain: true" in ajax-request, tried use jsonp (which worked get-requests) nothing helped.

is there proper way solve this? read problem might solved ajax authentication. correct , how can achieve that?

to solve problem following

create global.asax , add following enable ajax cross-domain post

 public void application_beginrequest(object sender, eventargs e)         {             httpcontext.current.response.addheader("access-control-allow-origin", "*");             httpcontext.current.response.addheader("access-control-allow-methods", "get, post,options");              if ((httpcontext.current.request.httpmethod == "options"))             {                  httpcontext.current.response.addheader("access-control-allow-headers", "content-type, accept");                 httpcontext.current.response.addheader("access-control-max-age", "1728000");                 httpcontext.current.response.end();             }         }     } 

at service set

[aspnetcompatibilityrequirements(requirementsmode =     aspnetcompatibilityrequirementsmode.allowed)]     public class yourservicename : yourservicenameinterface 

Comments