Dual Service Example
This example shows how easy it is to start using RestCake by modifying your existing WCF services to also work through RestCake. There is only a single service class at work here (see /Examples/Services/WcfAndRestCakeDualService.cs). It was a WCF REST service to start with. To add RestCake functionality, we made the class inherit from RestHttpHandler (previously, the class had no base class), and then set up a GenericHandlerRoute<T> in the Global.asax in registerRoutes().

The base service url for WCF is //services/dual_wcf/
The base service url for RestCake is //services/dual_rest/

I recommend using Firefox with Firebug to watch the net traffic (select the Net tab, and filter by XHR). You'll be able to easily see the GET, PUT, POST and DELETE async requests, inspect the headers, and look at the responses (both raw and as json objects).

Notice the difference in the date formats when switching between WCF and RestCake (I don't do any date "fixing up" for WCF here). Also, if you look at the service implementation, you'll see that it's necessary to strip out all cycles from the object graph before returning the result. This is because the WCF REST DataContractJsonSerializer cannot handle cycles, and it would cause a runtime exception. The default behavior for RestCake (which uses Json.NET for serialization) is to ignore cycles, so they would get stripped out automatically, and you wouldn't have to worry about doing this from your service methods.

Note: If your existing WCF REST service uses WebOperationContext, it will throw a NullReferenceException. RestCake currently has no support for this (I don't know how to create a WebOperationContext based on an existing HttpContext). If your WCF servcie was only being used via HTTP in the first place (an no other hosting mechanisms), then you can safely trade out any usage of WebOperationContext.Current with HttpContext.Current.
Operations
Raw Results
Url

Data sent (method = )

Received (select)
PersonDto Results
Clear table
Method ID DateCreated DateModified Fname Lname Emails Addresses    
Create new person
samscode.com rest.codeplex.com loef.codeplex.com
©2010 samscode.com, Samuel Meacham