WCF ResponseFormat JSON returns Json in Fiddler, Xml in Chrome / Firefox!

Hi, I have a WCF Rest 4.0 project. For some reason, I have a webservice that Json should return, and it does if I am at the endpoint on top of the script, but through firefox or chrome if I type the address that I get xml. What's happening???

Thanks for any help! Here is the code.

Web service:

[OperationContract] [WebGet(UriTemplate = "", ResponseFormat = WebMessageFormat.Json, RequestFormat = WebMessageFormat.Json)] public SomeObject [] GetObjects() { ..... 

Object Code:

 [DataContract] public class SomeObject { [DataMember] public string Date { get; private set; } .... public String Site { get; private set; } 
+6
json c # wcf
source share
4 answers

If you are using the .NET 4.0 platform, this solution is: http://karnicki.eu/2011/02/rest-wcf-net-4-0-service-with-json-jsonp-for-jquery/

WCF now has JSONP support out of the box with a small configuration.

Basically you just need to edit / add two entries of the configuration file, authenticationMode and StandardEndpoint and voila, you can view the json response from your WCF service in any browser.

EDIT: the original link is not working - this may help: http://blog.shutupandcode.net/?p=696

+1
source share

I posted this as a comment, but here I will tell you more.

Your browser will most likely send this header:

 Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8 

Note that it does not mention json, but mentions xml.

Your WCF client most likely uses a different Accept header, which gives preference to json. You can check this in feeddler.

+2
source share

Browsers cannot display raw JSON, however you can use a tool like JSON viewer ( http://jsonviewer.codeplex.com/wikipage?title=Home&ProjectName=jsonview ), or Fiddler is suitable for this job.

0
source share

I had the same problem. I used WCF configuration without svc .

I had to change this boolean in the web.config file with true:

 <standardEndpoint name="" helpEnabled="true" automaticFormatSelectionEnabled="true"/> 

to false:

 <standardEndpoint name="" helpEnabled="true" automaticFormatSelectionEnabled="false"/> 
0
source share

All Articles