If you used .NET 4.0 or 4.5, it would be simple - either use the automatic format selection, as suggested by Vibin Kesavan, or set WebOperationContext.Current.OutgoingResponse.Format in JSON or XML as part of the operation, depending on some of your logic.
For 3.5, you need to do most of the work. This post has an implementation of this particular scenario. You need to create a special implementation for formatting send messages that (probably) wraps two formatting, one for JSON and one for XML. And when serializing the answer, decide which formatter to use based on your logic.
carlosfigueira
source share