Sunday, June 12, 2011

Getting 400 Bad Data when using svc for AJAX calls

You may run into problems when using WCF service for AJAX calls. I've described how to use it in this post. Turns out, there's one small thing in configuration, that can cause all sorts of problems.
I've named the service "MyService.svc". Registered everything, configured in web.config, but I was still getting errors during load - essentially the ".../MyService.svc/js" (or ".../jsdebug" in debug mode) was returning 400 Bad Data error.
I've finally pinned the problem to web.config setting - the name attribute of the service has to match the class name.
So this is wrong:
<service name="aaaMyService">
...

And this is correct:
<service name="MyService">