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, MonoTouch for iPhone, MonoDroid for Android, and Windows Azure.

News

Personal Blog

Work 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

Twitter Trackbacks for Wrapping your WCF Responses - Wallace B. McClure [asp.net] on Topsy.com said:

Pingback from  Twitter Trackbacks for                 Wrapping your WCF Responses - Wallace B. McClure         [asp.net]        on Topsy.com

# January 19, 2011 1:37 AM

Jason Haley said:

Interesting Finds: January 20, 2011

# January 20, 2011 7:07 AM

Wrapping your WCF Responses | Object Oriented Programing said:

Pingback from  Wrapping your WCF Responses | Object Oriented Programing

# April 24, 2011 8:07 AM