lørdag, mai 21, 2011

Fixing the WCF JSON "application/json" not expected, but 'text/xml; charset=utf-8' was error

415 Cannot process the message because the content type 'application/json; charset=UTF-8' was not the expected type 'text/xml; charset=utf-8'.

I got stuck on this error when making a JSON WCF service in ASP.NET using .NET 4 today, another interface worked just fine. Figured out by comparing them that the markup for the faulty .SVC was missing this declaration:

Factory="System.ServiceModel.Activation.WebServiceHostFactory"

In full it should have read


<%@ ServiceHost Language="C#" Debug="true" Service="WebPages.Interfaces.example" CodeBehind="example.svc.cs" Factory="System.ServiceModel.Activation.WebServiceHostFactory" %>

, but it actually read

<%@ ServiceHost Language="C#" Debug="true" Service="WebPages.Interfaces.example" CodeBehind="example.svc.cs" %>

0 kommentarer:

Legg inn en kommentar