WCF Data Services supports returning JSON. However, the default WCF Data implementation does not support the $format query option and uses only the value of the Accept header of the request. There cases when your WCF Data service need to support the $format query option, e.g. when the client can’t set the Accept header.
Suppose, you have generated a WCF Data Service based on OpenAccess Domain Model by using the Add OpenAccess Service wizard.
If you try to run the following query: http://localhost:12687/NorthwindService.svc/Orders?$format=json
You will be presented with this error: The query parameter '$format' begins with a system-reserved '$' character but is not recognized.
To enable support for JSON:
- Download the needed code from the Microsoft Code Gallery.
- Locate the JSONPSupportBehavior.cs file in the downloaded project and include it in your web project.
- Add a reference to System.Runtime.Serialization.dll.
- Mark your service with the JSONPSupportBehavior attribute.
[System.ServiceModel.ServiceBehavior(IncludeExceptionDetailInFaults = true)]
public partial class NorthwindService : OpenAccessDataService<WebApplication.EntitiesModel>