Tuesday 16 August 2011

Posting JSON to a Restful WCF service

This should be simple, but WCF isn't very forthcoming when it comes to deserialization errors.


To get this working with an out-of-the-box .Net 4 Rest WCF service:

  1. Start Fiddler.
  2. Go to Fiddler's Request Builder, and select the Raw tab.
  3. Establish the POST URI, and the format of the POST data (this will be shown on the service's help page).
  4. Copy, paste and edit the below sample request.
  5. Execute the request.
Points to note:

  1. The POST address must end in a slash: http://localhost:57036/endpoint/.
  2. The Content-Type must be set to application/json.
  3. The Content-Length must be match the size of the body.
  4. The body's format must be the correct JSON representation of the object. If in doubt check the service's help page.

No comments: