I just created my first WCF REST service. I wanted it to return JSON, so I highlighted the response format. At first I was upset because he was returning SOAP all the time, and I did not know why, but I saw that the blogger was using Fiddler, so I tried with it and then received a JSON response.
I think the reason is that Fiddler does not send this HTTP header:
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
But then I tried to process the request using this header:
Accept: application/json,text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
But that did not work. How does WCF decide when to use JSON or SOAP?
Is there a way to force JSON back?
I would like to be sure that when I use the service, it will return JSON, not SOAP.
Thanks.
Update : Code example:
[ServiceContract] [AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Required)] [ServiceBehavior(InstanceContextMode = InstanceContextMode.PerCall)] public class Service1 { [WebGet(UriTemplate = "", ResponseFormat = WebMessageFormat.Json, RequestFormat= WebMessageFormat.Json)] public List<SampleItem> GetCollection() {
source share