I am creating a WCF data service (with .net 4.5 VS 2012) using the Reflection Provider (http://msdn.microsoft.com/en-us/library/dd728281.aspx) for existing classes. I can successfully access the service using "Accept: application / atom + xml" in the request header. however, when I change the "Accept" to "application / json" in the request header, I received the error "Unsupported media type." As I found out, the WCF data service supports JSON, what should I do to enable json data request in the service?
thanks
Edit: I embed my code below: I first defined the product class:
[DataServiceKeyAttribute("Id")] public class Product { public int Id { get; set; } public int Price { get; set; } public string Name { get; set; } }
then I have a ProductContext class:
public class ProductContext { private List<Product> products = new List<Product>(); public ProductContext() { for (int i = 0; i < 100; i++) { var product = new Product(); product.Id = i; product.Name = "ID - " + i.ToString(); product.Price = i + 100; products.Add(product); } } public IQueryable<Product> Products { get { return products.AsQueryable(); } } }
and my ProductService.svc.cs
[System.ServiceModel.ServiceBehavior(IncludeExceptionDetailInFaults = true)] public class ProductsService : DataService<ProductContext> {
source share