get underlying response stream from WebOperationContext
How do I get access to the un开发者_如何学编程derlying response stream from a WebOperationContext?
Change the return type of the method to Stream.
The code I use for returning an html/text stream is:
public Stream GetHTML()
{
MemoryStream stream = new MemoryStream();
StreamWriter writer = new StreamWriter(stream, Encoding.UTF8);
writer.Write("HTML STRING");
conn.Close();
writer.Flush();
stream.Position = 0;
WebOperationContext.Current.OutgoingResponse.ContentType = "text/html";
return stream;
}
Obviously you'll have a different content type, and I don't think you'll have to use UTF8 encoding.
精彩评论