Error 400 with WCF REST Services
I recently worked on a site that had a strange issue where “sometimes” the WCF service (JSON encoding) that we accessed via JavaScript (using jQuery) was throwing an HTTP 400 error. Setting a breakpoint at the web method itself was useless as it would never be hit.
Well, it turns out it was a simple problem – WCF throws this error internally (via the JSONP Encoder) whenever a parameter cannot be parsed into the correct type. In this case, an int parameter value was being read from a cookie that was returning null. Changing the code to pass a -1 instead of null worked just fine. In retrospect, it might even be smarter to pass the paramters as strings and parse them yourself. At least that way you can control what formats are allowed and, moreover, you’ll understand what the devil is going on!
more later – joel