Several months ago, Microsoft decided to change up the HttpResponseMessage class. Before, you could simply pass a data type into the constructor, and then return the message
For any T object you can do:
return Request.CreateResponse<T>(HttpStatusCode.OK, Tobject);
You can create your own specialised content types. For example one for Json content and one for Xml content (then just assign them to the HttpResponseMessage.Content):
public class JsonContent : StringContent
{
public JsonContent(string content)
: this(content, Encoding.UTF8)
{
}
public JsonContent(string content, Encoding encoding)
: base(content, encoding, "application/json")
{
}
}
public class XmlContent : StringContent
{
public XmlContent(string content)
: this(content, Encoding.UTF8)
{
}
public XmlContent(string content, Encoding encoding)
: base(content, encoding, "application/xml")
{
}
}