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.

1 Comment

Comments have been disabled for this content.