1

I am writing a RESTful api using WCF Web Api Preview 6. I've just spent most of the day figuring out that it doesn't like "prettified" Json! I have a method which produces "human readable" Json, ie - it spreads the text over multiple lines to make it look nice ...

{
  "fieldname": "value"
}

I eventually track down a strange problem I was having to the fact that I had pretty Json. If I changed it to this ...

{ "fieldname": "value" }

... it worked perfectly.

BUT, if I pasted the first example into the test client then it worked perfectly. Since it worked I dismissed that as being the cause very early on in my investigations. But, I came back around to it after having eliminated every other possibility.

The error I was getting was a bit misleading ...

System.InvalidOperationException: The service operation 'Post' expected a value assignable to type 'MyType' for input parameter 'resource' but received a value of type 'HttpRequestMessage`1'.

So, my question is. Does the test client do something to the body of the request to make it work with the built-in serializer?

Antony Scott
  • 21,690
  • 12
  • 62
  • 94
  • please provide the api method signature you are calling and your full poco code of MyType (with serialization code, if used). – SeriousM Apr 12 '12 at 07:48
  • This was a question regarding the deserialisation and why it works for badly formed json when using the test client, but since the wcf web api is no more it's not really a relevant question anymore. I'll close it. Apologies for any confusion caused. – Antony Scott Apr 12 '12 at 08:53

0 Answers0