如何将此输出写入流?我希望将元素以文本/xml格式写入流。我只是想创建简单的REST服务。我想使用element.Save方法。
<%@ WebHandler Language="C#" Class="Calculation" %>
using System;
using System.Web;
public class Calculation : IHttpHandler {
public void ProcessRequest (HttpContext context) {
int numberCalculation = 0;
if (context.Request != null)
numberCalculation = int.Parse(context.Request.QueryString["number"]);
context.Response.ContentType = "text/xml";
System.Xml.Linq.XElement element = new System.Xml.Linq.XElement("Result", new System.Xml.Linq.XElement("Results", numberCalculation * 5));
}
public bool IsReusable {
get {
return false;
}
}
}发布于 2009-11-12 11:10:21
using (var xmlWriter = System.Xml.XmlWriter.Create(context.Response.OutputStream))
{
element.Save(xmlWriter);
}https://stackoverflow.com/questions/1719578
复制相似问题