I created a new wcf rest service using .net 4. I have created a new service based on the example one and referenced it in the global.asax file so I can browse to it ok.
My problem is I get the results back in xml not json. This is my service code
[ServiceContract]
[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
[ServiceBehavior(InstanceContextMode = InstanceContextMode.PerCall)]
// NOTE: If the service is renamed, remember to update the global.asax.cs file
public class CheckIfValid
{
[OperationContract]
[WebGet(UriTemplate = "/{id}/details.json",
ResponseFormat = WebMessageFormat.Json)]
public SampleItem Get(string id)
{
// TODO: Return the instance of SampleItem with the given id
//throw new NotImplementedException();
if(id=="123")
return new SampleItem { Id = 1, StringValue = "Got it" };
else
return new SampleItem { Id = 2, StringValue = "Not valid fool..." };
}
}
Very basic but I am just trying to get my head around it. The returned result looks like this
<SampleItem xmlns="http://schemas.datacontract.org/2004/07/WcfRestService1" xmlns:i="http://www.w3.org/2001/XMLSchema-instance"><Id>1</Id><StringValue>Got it</StringValue></SampleItem>
I have tried browsing to the help section in the service but the json example doesnt do anything.
Can anyone suggest what I should be doing differently?