Wrapping your WCF Responses (or should it be Christmas Presents) - More Wally - Wallace B. McClure
in

MoreWally.com

Giving people what they want, More Wally. This is the technical and personal blog site of
Wallace B. (Wally) McClure.

This Blog

Syndication

News

Please goy buy 3-4 copies of my book on MonoTouch titled "Professional Android Programming with Mono for Android for .NET/C# Developers." They make great gifts all year round. Plus, I get about $.25 when you buy a copy.

Technical Sites

More Wally - Wallace B. McClure

This blog will have all kinds of posts about Wally McClure. In it, there will be tons of .NET and computer programming posts as well as Wally's views on life in general. As you might guess, this site and blog help you get More Wally in your life. What more could anyone want? iPhone, Android, MonoTouch, MonoDroid, Mobile, HTML5, .NET, ADO.NET, ASP.NET, AJAX, jQuery, jQuery Mobile, ASP.NET AJAX, and Windows Azure............follow me on twitter at Wally

Wrapping your WCF Responses (or should it be Christmas Presents)

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

No Comments
2006 - Wallace B. McClure
Powered by Community Server (Non-Commercial Edition), by Telligent Systems