.netrestweb-serviceswcf

WCF as a web service with the smallest possible payload


I do most of my work with Microsoft technologies these days, so naturally I'm checking out what WCF has to offer. It seems very flexible and a great next step up from .Net remoting, but it seems very tied to SOAP messages and quite a bit clunky for a platform agnostic web service app. I'm not an expert on the technology, but I imagine all of this flexibility they're touting means that you can break away from SOAP messages and return whatever data structures/format you want. Is this true or false?

The reason I say this is that if I really wanted to create an application as a REST service, one of my target platforms would be mobile. Not just that, one important goal of any web based service is to keep the data payload small whether for a mobile at dial up speeds or a full desktop app.

So, if you take Twitter's API as an example, it has been incredibly successful because you can request the data as JSON with no fancy SOAP envelopes weighing the data down and receive the smallest amount of bytes to represent the data you want. So a mobile application running on a device with poor connectivity consuming Twitter's data can use the least amount of bandwidth possible. Besides that, the pattern of Twitter, Facebook, or any of the more successful public API's is a custom data structure in JSON and/or XML and not wrapped in a SOAP envelope (though I could be wrong... this is just my impression).

How would you do this in WCF? Do you have to jump through hoops to tell WCF to "just return this text...don't worry about the SOAP envelope", or is it a simple config option?


Solution

  • See WCF RESTful POX, JSON and SOAP Coexist. It's actually very simple to configure WCF to return simple POX and/or JSON.