Xml MVC WAB API对象作为HttpResponseMessage的HttpContent
我有一个MVC WEB API服务,我想将每个响应作为HttpResponseMessage发送。 在这个案例中,我有一个类似这样的类:Xml MVC WAB API对象作为HttpResponseMessage的HttpContent,xml,json,model-view-controller,httpwebrequest,Xml,Json,Model View Controller,Httpwebrequest,我有一个MVC WEB API服务,我想将每个响应作为HttpResponseMessage发送。 在这个案例中,我有一个类似这样的类: public class Quota { public int docs_quota { get; set; } public int pages_quota { get; set; } public int size_quota { get; set; } } 在响应的内容中,我想发送一个配额对象,但我不想自己序列化它,我想让服务来
public class Quota
{
public int docs_quota { get; set; }
public int pages_quota { get; set; }
public int size_quota { get; set; }
}
在响应的内容中,我想发送一个配额对象,但我不想自己序列化它,我想让服务来做,所以我不必担心它是否序列化为json或xml
我该怎么做
真诚地
Zoli最终,我发现,这很容易:
Quota q = GetQuota();
var response = new HttpResponseMessage<Quota>(q);
return response;
它将返回一个状态码200okay,q将在内容中以json/xml进行序列化