what is the best way to create a JSONP web service so I can call JSON with a normal xhrGet? I am using ASP.NET 4.0. I have searched online but it only shows ASP.NET 3.5 and under.
-
Also this is in C# if that matters. – Darren Dec 7 '11 at 0:03
-
You should use WCF for all new web service development, and not the legacy ASMX services. Alternatively, use ASP.NET MVC to create the service. – John Saunders Dec 7 '11 at 0:09
On .net 4.0 you can set crossDomainScriptAccessEnabled on a webHttpBinding and have WCF handle the rest for you.
I can't post my own code, but this article was extremely helpful in figuring that stuff out for me.
Note though that in JSONP, unhandled exceptions cannot be caught properly.
-
1This was a perfect link. I've been lamenting for ages not being able to get it to work (ages in Konrad-time, that is - it's about a day or two in human time). Less than 15 minutes after the article I got me a working example. Huge thanks! – Konrad Viltersten Jun 20 '13 at 17:45