Follow me on Twitter at Twitter.com/wbm
FYI, I'm blogging most of my stuff over at More Wally now.
You might want to add my rss feed to your reader at:http://morewally.com/cs/blogs/wallym/rss.aspx
Wrapping your WCF Responses - Wallace B. McClure

Wallace B. McClure

All About Wally McClure - The musings of Wallym on Web, HTML5, Mobile, Xamarin.iOS, Xamarin.Android, and Windows Azure.

News

Visual Studio Magazine Column Personal Blog

.NET

Book Authors

Business

Family

Friends

Georgia Tech Bloggers

Personal

Archives

Wrapping your WCF Responses

I've got a WCF web service that exposes its data over REST.  I'm calling it from iPhone and Android.  The method signature is something like:

    [WebInvoke(UriTemplate = "/UserValidate",
    Method = "POST",
    BodyStyle = WebMessageBodyStyle.Wrapped,
    RequestFormat = WebMessageFormat.Json,
    ResponseFormat = WebMessageFormat.Json)]
    public bool UserValidate(string user, string pwd);

In the response, I've been getting something like this:

{ "UserValidateResult": { true } }

This is crap as all I wanted is { true } or { false }. You can imagine that when there was a bigger result coming back how this would complicate things.  I just want my basic data, nothing more or less.  How the heck do you get rid of the additional "UserValidateResult" junk.  Well, now we know.  See that BodyStyle attribute on the interface?  Change it to:

BodyStyle = WebMessageBodyStyle.WrapperRequest

Now, it seems to pass back what I need, which is { true / false }

PS.  Hopefully, I didn't mangle this entry as its not been pulled 100% from my project. I can't just copy this code in.

PSS.  Thanks to my buddy Nathan Blevins for pointing me in the right direction.

Comments

joon said:

It amazes me just how powerful the custom field section is, the possibilities seem to be endless.

# January 18, 2011 9:39 AM