WCF REST Url Request Returns a 404 Error

This error occurs because IIS is doing the right thing as far as it knows, and WCF wants more! Background – WCF REST implementations allow you to expose web service methods via url mappings. For example, a server “myservice.svc” has a method “Test”. This could be accessed by the url http://theserver/myservice.svc/Test in a standard web browser. WCF automatically maps the url to the appropriate web service method and returns the results. This is incredibly useful for testing when you just want to get some web service results to view the data, and works well with applications/technologies (like json and silverlight) that can access data via urls rather than having to use SOAP.

The problem for me occurred when trying to deploy my new services to a test server. The services installed fine, I could view the WSDL from the auto-generated WCF metadata, but as soon as I requested a web service method I got a 404 error. After some serious research and pulling bits from MSDN, forum postings, IIS logs, and way too much trial-and-error, the trick seems to be to ensure that the .svc mapping in IIS does not try and validate the url. It should just pass the work over to WCF. To check this:

1. Open IIS admin console
2. Open your services virtual directory/application properties
3. In Application Settings, click Configuration
4. On the Mappings tab, in the Application Mappings section, locate and highlight the .svc entry and click the Edit button
5. Ensure the “Check that file exists” check-box is *not* checked
6. Click OK
7. Restart IIS (stopping the website doesn’t appear to be enough)

This should fix the problem! By ticking the “Check that file exists” box, you are instructing IIS to validate the URL before it passes off to the mapped application. Because the URL  http://theserver/myservice.svc/Test doesn’t actually exist, IIS dutifully returns a 404 error. By un-ticking this box, IIS will just make sure the .svc file exists, then hand off to the aspnet_isapi.dll to do its WCF magic.

Note that if you can’t view the metadata for your service, there are other problems to check as well, like making sure .NET Framework 3.5 is installed, your web app uses .NET 2.0 instead of .NET 1.1, and that your configuration file is correct.

HTH someone save a week like I just spent finding out what was wrong!


One Response to “WCF REST Url Request Returns a 404 Error”

  1. guy Says:

    awsome post dude thank you

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: