views:

251

answers:

1

I've been banging my head against the wall for the past couple of hours, here's what we're trying to do: a method expects a primitive/simple type as the request body. Originally we tried with a boolean, but that didn't work so we tried with string and object. Same thing.

Here's the server-side code

[OperationContract]
[WebInvoke(UriTemplate = "/foo/{foo_id}/bar", Method = "POST", ResponseFormat=WebMessageFormat.JSON)]
string G(string foo_id, string content);

And here's the request in Fiddler:

Header:

User-Agent: Fiddler
Host: localhost
Content-Type: 'application/json',
Content-Length: 19

Body:

"hello_world"

We tried to wrap "hello_world" in a json object, like {"content":"hello_world"} but no luck.

Any thoughts?

A: 

Hi Oliver -works fine for me, here's my code:

[OperationContract]
    [WebInvoke(UriTemplate = "/foo/{foo_id}/bar", Method = "POST", ResponseFormat = WebMessageFormat.Json, RequestFormat = WebMessageFormat.Json)]
    public string G(string foo_id, string content)
    {
        return content + foo_id;
    }

You didn't set the request format (a pain I know :))

Here's my Fiddler request User-Agent: Fiddler Content-Type: application/json Host: localhost:54287 Content-Length: 7 "Hello"

Jon Flanders
I thought the request format was picked up dynamically based on the content/type?
Oli
No, that's what HTTP should do, and one of numerous features WCF REST doesn't have.
serialseb