Monday, 15 March 2010

json - AJAX Cross Domain request to WCF service without using jsonp -


I am using a WCF service and currently it is used by a Silverlight application. Client in WCF service is AccentuPolicy.exml and Cross Domain.exml, so this is why there is no problem in requesting Silverlight, however the request comes from a different domain.

Now I understand that, by connecting the following line of code on the web config of the WCF service, using NAT 4.0 or later, jsonp

I am thinking that if I edit the global.asax of the WCF service with the snippet at the bottom of the code Will I be able to successfully create AJAX cross domain requests? Protected Zero application_BeginRequest (Object Sender, EventArgs e) {EnableCrossDomainAjaxCall (); } Private Zero EnableCrossDomainAjaxCall () {HttpContext.Current.Response.AddHeader ("Access-Control-Permission-Origin", "*"); If (HTTPTPText.content. Request) HTTP method == "OPTION") {HTTPCTX. Corrente response. Adherer ("Access Control-Aces-Methods", "GET, Post"); HttpContext.Current.Response.AddHeader ("Access-Control-Permission-Header", "Content-Type, Accept"); HttpContext.Current.Response.AddHeader ("Access-Control-Max-Age", "1728000"); HttpContext.Current.Response.End (); }}

Please note that I am having trouble for the deployment of the WCF project, so I should only know that I am taking the right perspective.

  Secure void Application_BeginRequest (Object Sender, EventArgs e) {EnableCrossDomainAjaxCall (); } Private Zero EnableCrossDomainAjaxCall () {HttpContext.Current.Response.AddHeader ("Access-Control-Permission-Origin", "*"); If (HTTPTPText.content. Request) HTTP method == "OPTION") {HTTPCTX. Corrente response. Adherer ("Access Control-Aces-Methods", "GET, Post"); HttpContext.Current.Response.AddHeader ("Access-Control-Permission-Header", "Content-Type, Accept, Foo"); HttpContext.Current.Response.AddHeader ("Access-Control-Max-Age", "1728000"); HttpContext.Current.Response.End (); }   

}

did the trick

In my case, I had to add a custom header named Fu as an example, Client side had to pass

Hope it helps someone!

No comments:

Post a Comment