Reputation: 1342
I'm trying to post a json string to a .net wcf service.
Here's the definition of the operation:
[WebInvoke(Method = "POST", UriTemplate = "test/")]
[OperationContract]
[Description("Test")]
void Test(string input);
I use fiddler to send my test. Here's fiddler info:
POST http://localhost/test.svc/test/ HTTP/1.1
Content-Type: application/json
Host: localhost
Content-Length: 4
test
I always receives this http 400 error:
There was an error deserializing the object of type System.String. The token 'true' was expected but found 'test'.
What am I doing wrong? I'm sure it's probably something really obvious, but I'm on it since this morning...
The problem has been broke down to it's most simple expression. In the real world, we want to post a string that is in fact JSON. But we don't want .net to handle the deserialization, we want to do it ourself on our own, in the service.
Upvotes: 2
Views: 2846
Reputation: 87218
The request content
test
Is not valid JSON. You need to send the string within quotes:
POST http://localhost/test.svc/test/ HTTP/1.1
Content-Type: application/json
Host: localhost
Content-Length: 6
"test"
Upvotes: 7