Geeks With Blogs
David Douglass .NET on My Mind

I put together a WCF REST over HTTP service and learned a few things along the way.

Sample Project

The best way to learn about WCF REST is to examine the sample project supplied by Microsoft.  This is available at Windows Communication Foundation (WCF) and Windows CardSpace Samples.  Once you unzip the download you'll find C# and VB sample projects at TechnologySamples\Scenario\PoxMessaging.  These simple projects demonstrate everything you need to know.

Creating Your Own Project

The Visual Studio project template for creating a service hosted by IIS isn't grouped with the WCF projects but is with the ASP.NET projects:

create new project

Once you have a project created, just follow the pattern in the sample and you'll quickly be ready to test.

Testing Your Project

The easiest way to test your project is to use Fiddler 2.  Fiddler 2 includes a tab that lets you form and send HTTP requests:


Just select your verb (GET, PUT, etc.), enter the service URL, enter your HTTP headers, paste your XML into Request Body, and press Execute!  Content-Type should be text/xml; Fiddler 2 will automatically calculate the Content-Length header for you.  The result will appear in the left pane; you can double click on the line and get a detailed look at the request and response using the Session Inspector.

HTTP Status Code 415 Unsupported Media Type

If you've been following along exactly, your service should be returning a HTTP Status Code 415 Unsupported Media Type.  This is because when the project was created in Visual Studio there was an assumption that SOAP would be used.  Switching to REST means changing the binding in the web.config file:

<system.serviceModel> <services> <service name="MyService.Service" behaviorConfiguration="MyService.Service1Behavior"> <!-- Service Endpoints --> <!-- use webHttpBinding for REST instead of wsHttpBinding --> <endpoint address="" binding="webHttpBinding" contract="MyService.IService">

Note that this page, which is supposed to list all the System-Provided bindings, doesn't mention webHttpBinding.

Posted on Monday, February 4, 2008 9:59 PM | Back to top

Comments on this post: WCF REST over HTTP Service

# re: WCF REST over HTTP Service
Requesting Gravatar...
I tried your web.config settings on one of the sample projects (Counter project) from the starter kit but it kept complaining about not finding the contract name. Can you tell me what's wrong with my web.config?

<?xml version="1.0"?>
<compilation debug="true"/>
<service name="Counter.Service" behaviorConfiguration="webHttp">
<endpoint address="" binding="webHttpBinding" contract="Counter.ISingletonService" />
<behavior name="webHttp" />

<serviceHostingEnvironment aspNetCompatibilityEnabled="true"/>
Left by notlkk on Jan 05, 2009 8:51 PM

# re: WCF REST over HTTP Service
Requesting Gravatar...
Thank you for posting this, I've be banging my head against the wall on this one.
Left by James Norman on Mar 09, 2009 12:38 PM

# re: WCF REST over HTTP Service
Requesting Gravatar...
See this:

Problem fixed with FW 4
Left by gromas on Jun 25, 2010 8:27 AM

# re: WCF REST over HTTP Service
Requesting Gravatar...
where is the rest of the tutorial
Left by ايفون السعوديه on May 25, 2011 3:24 AM

Your comment:
 (will show your gravatar)

Copyright © David Douglass | Powered by: | Join free