Passing a Primitive Type to a WCF RESTful Service
I've been banging my head against the wall for a few hours now, here's what we're trying to do: the method expects a primitive / simple type as the request body. We originally tried with boolean, but it didn't work, so we tried using string and object. Same.
Here's the server 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 to Fiddler:
Title:
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?
+1
a source to share
1 answer
Works great 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 haven't set the request format (pain I know :))
Here's my Fiddler request:
User-Agent: Fiddler
Content-Type: application/json
Host: localhost:54287
Content-Length: 7
"Hello"
+2
a source to share