Reputation: 2299
I've a strange problem using my web service :
When I, as a client, POST a form to the REST Web Service without setting any "type-content" header, things works fine. I get the call on the server and the Json text is available.
If I, as a client, sets the content-type header of my post request to "application/json", the server reply by a "Bad Request (400)".
The web service method is :
<WebInvoke(UriTemplate:="Login", Method:="POST")>
Public Function LoginFormAccess(data As IO.Stream) As String
(...)
end function
If I don't mention "Application/Json", I can retrieve the client json-typed body, posted in the data stream. If I do, I get the Bad Request answer.
Why is there a such great difference of behavior concerning the content-type value and what is provide such a difference ? Does the method needs another type of parameter, or something else has to be changed or checked?
ADDED : If the content-type is "Application/Json" AND the body is empty, then it works...!
Note 1 : The class responsible to answer the call is instantiated. (A trace in the new() proves it). So, the problem seems to be that the server does not find a proper method to call on that object...
Note 2 : I've this problem using different clients, so I'm pretty sure is a server-side problem.
Note 3 : I've used a WCF REST Service Application Template to create my project.
Note 4 : Mentioning "ResponseFormat=WebMessageFormat.Json" and "RequestFormat=WebMessageFormat.Json" does not help.
Upvotes: 2
Views: 6228
Reputation: 34218
When you add a content-type
header to your request, you are specifying the content type of the data in your request, not the content you expect to see returned.
My bet from what you've posted is that you are posting XML to the service, and when you set content-type
to JSON you are breaking the server's ability to parse the body. Your ambiguous statement that it works "If the content-type is "Application/Json" AND the body is empty" might bear this out (assuming you mean the body of your request, not of the response).
You could prove this by adding a content type of XML instead of JSON - which, if it matches the actual body of your request, will work just fine.
In short: it's giving a "Bad Request" error because your request is specifying JSON content and you are not sending JSON.
Upvotes: 1