2

I have a simple REST web service in WCF that is declared as follows:

[WebInvoke(Method = "PUT",UriTemplate = "comptatge/add",RequestFormat = WebMessageFormat.Json,ResponseFormat = WebMessageFormat.Json)] public void GravaComptatge(MyDataContract contract) { ... } 

where MyDataContract is a class with simple properties.

Now I send a put Request using fiddler to see if it works OK. In the body I send JSON with the same properties as MyDataContract but it's not working. I get a 400 Bad Request HTTP error. What am I doing wrong here? The service is hosted in a MVC app using ServiceRoute. Other GET services work OK.

1 Answer 1

9

This happened to me before, and adding Content-Type: application/json in the request headers was the solution.

Sign up to request clarification or add additional context in comments.

1 Comment

When using xml as your data format the content-type string is conveniently 'application/xml'.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.