I just finished my first WCF 4.0 Rest service and donβt understand why the Content-Type of the returned data changes between calling the service through Fiddler and Firefox. Here is my service contract:
[ServiceContract] public interface IProjectService { [OperationContract] [WebGet(UriTemplate = "project/{id}/json", BodyStyle = WebMessageBodyStyle.Bare, ResponseFormat = WebMessageFormat.Json)] ProjectDataContract GetProjectJson(string id); [OperationContract] [WebGet(UriTemplate = "project/{id}/xml", BodyStyle = WebMessageBodyStyle.Bare, ResponseFormat = WebMessageFormat.Xml)] ProjectDataContract GetProjectXml(string id); [OperationContract] [WebGet(UriTemplate = "userprojects/{userKey}/json", BodyStyle = WebMessageBodyStyle.Bare, ResponseFormat = WebMessageFormat.Json)] List<ProjectDataContract> GetProjectsByUserJson(string userKey); [OperationContract] [WebGet(UriTemplate = "userprojects/{userKey}/xml", BodyStyle = WebMessageBodyStyle.Bare, ResponseFormat = WebMessageFormat.Xml)] List<ProjectDataContract> GetProjectsByUserXml(string userKey); }
As you can see, I am adjusting the response format for each operation. If the request ends with "/ json", I return json data. If the request ends with "/ xml", then the XML data is returned. At least these are my intentions.
When I make a call to http: // localhost: 5050 / ProjectServiceLibrary / project / 27 / xml in Firefox, I see that the content type is set to "text / html", while the same request that is called in fiddler shows the correct type content "application / xml". The same thing happens when the suffix "/ json" is called - "text / html" in firefox and "application / json" in the violin.
So why is this happening? Who do I trust? I downloaded the Firefox JSONView add-in, but it all looks like json. It treats XML as JSON.
I am sure that I am missing something obvious. Any help would be greatly appreciated.
source share