views:

308

answers:

3

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?

+2  A: 

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

eed3si9n
+2  A: 

There are several configuration options you can set to remove the SOAP from WCF. The easiest thing to do is to use WebServiceHost rather than the usual ServiceHost class for hosting your services. It sets most of the options you'd want. Justin Smith has a good post that contrasts WebServiceHost and ServiceHost.

Although it sounds as if you're more worried about sending a POX (plain old XML) payload that some of the REST principles (URL mapping and HTTP methods), you might find Jon Flander's RESTful .NET book helpful. Here's an overview of Chapter 1.

Also check out the REST Starter Kit from Microsoft, which has lots of examples of how to do common web-oriented tasks with WCF.

And to answer the other part of your question, I've found that using JSON results in a far smaller payload than XML, while still having decent support within WCF.

dthrasher
Thanks...I'll probably pick up a copy of the book you linked.
Rich