Running into 400 & 500 error messages for WCF OData Services can be tricky to get past and even harder to sort through the red herrings out there. Here’s a few tips to attack any error messages you might run into.
Sweet! All done your spanky new OData services using Entity Framework in the back end and you’re feeling pretty awesome because a) it was stupid-easy to get going, and, #2 you are now the happy owner of a JSON data source with querystring filtering capabilities. Only trouble is, that darned thing won’t tick on your deployment server.
Don’t sweat it. There’s a dozen things that can sideways, but they’re all easy to fix.
If you’re going to host over HTTP, you’ll obviously have IIS installed, but make sure you light up all the right pieces. You’ll need .Net 3.0 and 4.5 installed and enabled. If you want HTTP activation, that may not be on by default. This MSDN article will get you there.
Some of the errors you’ll run into can most easily be solved by using what’s given to you for free. Check the Windows Event logs and drill into the details
If you’re not seeing much fruit from those efforts, you can also configure your service to use the verbose mode of error detail. This will likely reveal the juiciest information and is as easy as adding one line of code to your InitializeService method, as follows:
config.UseVerboseErrors = true;
If you’ve moved from dev to test or prod, you’ll need to make sure you update your connection strings. Nestled in several of those 400 error message are details about a problem connecting to the database or other insight related to your credentials or connections through EF in your EDMX.
I’ve run into 500’s a couple times, no information, just “internal server error”. This was because the application pool wasn’t set up for the correct version of .Net. Use the Advanced settings for your site in IIS to choose the app pool, or navigate IIS to the Application Pools and create a new one that matches the version of .Net for your service.
If you get 404.3, this is likely related to missing either the correct .Net components or the WCF Activation components (see MSDN article).
401’s that I’ve seen have been permissions related, naturally as they’re 401’s. Check your directory permissions if you’re doing something on the file system, and your DB credentials in your web.config. Remember that those EDMX’s have some funky formatting.
If you’ve got a night to invest in yourself I highly recommend reading the deeper bits on WCF Data Services. If you get serious, you’ll want to look into:
An indispensible tool in your kit is LINQPad – a must have for working with WCF OData.