We are builing a WCF Service which takes a message string as XML, does some processing on the XML and returns XML. We are looking into the idea of adding JSon results (and requests) as an option for users. And i have a question about how to impliment this
Since the service returns a string at the moment, containing the message in XML, i was thinking of adding a new paramater to the Method: Format. if this is XML, parse the incomming message as XML, do the magic and then return XML (much like what it is doing now). If that format is JSON, parse the JSON, do the Magic and return JSON… This will be as pluggable as posible: parse the input and turn into POCOs and pass on to the processing system, which returns POCOs to a Serilizer (for want of a better word) and return the text (be it XML or JSON currently) to the user.
Is this the correct way of doing this? The service is not a WCF Rest Service. We only have 1 method, and the Message we recieve is changed based on task being sent in. is this the right way to do this? any other sugestions?
WCF has 2 extensibility points that sound perfect for just such a situation: custom message inspectors and message formatters.
Incidentally, Carlos Figuera has a very good blog, which you may find useful if you use these extensibility points.