tags:

views:

104

answers:

1

Downloaded the WCF REST Template from this location.

The default response format is XML, which works great. However, when I try to get a JSON response, I still get XML.

This is my modified code -

[WebGet(UriTemplate = "",ResponseFormat = WebMessageFormat.Json)]
    public List<SampleItem> GetCollection()
    {
        // TODO: Replace the current implementation to return a collection of SampleItem instances
        return new List<SampleItem>() { new SampleItem() { Id = 1, StringValue = "Hello" } };
    }

Note the ResponseFormat=WebMessageFormat.Json. That is the only change I did to that template.

What am I missing?

Thanks!

+1  A: 

Figured out. 'automaticFormatSelectionEnabled' property for standardendpoint should be set to 'false' and defaultOutgoingReponseFormat should be set to Json.

<standardEndpoint name="" helpEnabled="true" automaticFormatSelectionEnabled="false" defaultOutgoingResponseFormat ="Json" />
Ryan