I want my WCF service to accept and respond to requests in JSON or XML. I thought that WCF was supposed to automatically interpret the response type based on the Accept header that the client specifies. However in my client request I specify the accept header to be application/json but I receive an XML response.
This is my service definition:
[OperationContract]
[WebInvoke(Method = "POST", UriTemplate = "/GetChecks", BodyStyle = WebMessageBodyStyle.Bare)]
Check[] GetChecks(MyCustomObj Object);
Im making the request here :
using (WebClient client = new WebClient())
{
client.Headers["Content-type"] = "application/json";
client.Headers["Accept"] = "application/json";
string response = client.UploadString(endpoint, JSONRequestString);
// Response is XML
}
I know I can make two endpoints and specify one as XML and the other as JSON but id rather not do this.
Any ideas?