Coffeehouse Post

Single Post Permalink

View Thread: A first-class REST framework for .NET
  • User profile image

    Well in my application I needed to return the data in 3 different formats.

    One was the default .Net serialization XML, the second was JSON, the third was custom XML. 

    One client of the service was a standard HTML JS application where the devs didn't know .Net so I chose REST services so I could use a simple address based API but allow querystring parameters to control which format is returned.

    WCF REST gave me the ability to use the same URL string i.e. /Posts /Topics etc but by appending ?format=JSON or ?format=XML I was able to service different clients.

    The power of WCF here was that I could use different contract methods mapped to the same URL.

    So for my custom XML methods I basically used the same domain objects but had a XML conversion layer that used XmlDocument to build up my custom xml then I just returned this document as a XmlElement. 

                WebInvoke(Method = "GET",
                            ResponseFormat = WebMessageFormat.Xml,
                            BodyStyle = WebMessageBodyStyle.Bare,
                            UriTemplate = "Topic/{topicName}")
    XmlElement GetTopics(string topicName);