我敢打赌,这不是最好的解决方案,但它现在正在为:
public class MyCustomFormatter : ActionFilterAttribute
{
public override void OnActionExecuted(HttpActionExecutedContext actionExecutedContext)
{
HttpResponseMessage response = actionExecutedContext.Response;
var contentType = response.Content.Headers.ContentType;
var oldContents = response.Content.ReadAsStringAsync().Result;
oldContents = oldContents.Replace("string", "myelement");
response.Content = new StringContent("<?xml version=\"1.0\" encoding=\"utf-8\"?>" + oldContents);
response.Content.Headers.ContentType = contentType;
actionExecutedContext.Response.Content = response.Content;
}
}
您要自定义从网络API发送XML? – 2013-02-22 15:13:17
嗨,是的,我正在寻找一种更简单的方式来返回像第一个片段的自定义XML。 – 2013-02-23 23:09:52