how to make wcf service method which returns the data in both xml and json, in short how to enable wcf service method which return dynamic output either xml or json.
[OperationContract] [WebInvoke(Method = "GET", BodyStyle = WebMessageBodyStyle.Wrapped, UriTemplate = "/ReturnTime?ReturnType={ReturnType}")] string ReturnTime(String ReturnType);
public string ReturnTime(String ReturnType) { if (ReturnType != "" && ReturnType != null) { if (ReturnType.ToUpper() == "STRING" || ReturnType.ToUpper() == "JSON" || ReturnType.ToUpper() == "XML") { if (ReturnType.ToUpper() == "JSON") return "[{\"Current Time is \":" + DateTime.Now.ToString() + "}]"; else if (ReturnType.ToUpper() == "XML") return "<CurrentTimeIs>" + DateTime.Now.ToString() + "</CurrentTimeIs>"; else if (ReturnType.ToUpper() == "STRING") return "Current time is : " + DateTime.Now.ToString(); else return "<CurrentTimeIs>" + DateTime.Now.ToString() + "</CurrentTimeIs>"; } else { return "<ErrorMessage><Message>" + ReturnType + " as returntype is not available. Please use JSON,XML OR STRING.</Message></ErrorMessage>"; } } else { return "<ErrorMessage><Message>Please provide Returntype either JSON,XML OR STRING.</Message></ErrorMessage>"; } }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)