tags:

views:

63

answers:

1

Hi everyone,

How can I write this output to the stream ? I want to write element to the stream as text/xml format. I am just trying to create simple REST service. I want to use element.Save method.

<%@ 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;
        }
    }

}
+2  A: 
    using (var xmlWriter = System.Xml.XmlWriter.Create(context.Response.OutputStream))
    {
        element.Save(xmlWriter);
    }
DSO
Thanks for the answer.
Braveyard