Return JSON AND XML format from .NET 3.5 WCF web service (REST)

I have an existing web service that returns XML responses, and I would like to add some new methods that return JSON. Do I need to create a separate web service that returns in JSON, or can I create a mix?

If I use ResponseFormat = WebMessageFormat.JSON, I need the service to be annotated using [DataContractFormat], but I don't seem to have this and the [XmlSerializerFormat], which is required for the response format like xml.

+5
source share
3 answers

, . [ServiceContract] ( DataContractFormat).

 [ServiceContract]
    public interface IDoStuff
    {
        [OperationContract]
        [WebInvoke(Method = "POST",
             UriTemplate = "DoStuff",
             ResponseFormat = WebMessageFormat.Json,
             RequestFormat = WebMessageFormat.Json)]
        TestObj DoWork(TestInputObj Inp);
    }

xml, responseformat. post, json, XML- xml.

+3

, XmlSerializerFormat? , XML, .

, . . , .

+1

, XmlSerializer " XML". , JSON. XML JSON. response.Content.ReadAsJsonDataContract<T>()/ReadAsXmlDataContract<T>() T XMLSerializable.

0

All Articles