인스턴스의 경우 IHttpHandler가 있습니다. 우리는 두 개의 가치가 있습니다 : XmlElement xmlResponse - 정말 큰 XML이 포함되어 있습니다. HttpContext 컨텍스트 - 현재 HttpContext입니다.ASP.NET에서 클라이언트에게 큰 XML을 효과적으로 보내는 방법은 무엇입니까?
간단한 솔루션 :
context.Response.Write(xmlResponse.OwnerDocument.OuterXml);
하지만 XML은 정말 큰 경우에 우리는 줄에서 OutOfMemoryException 얻을 수 있습니다. 호출 스택은 다음과 같이 표시됩니다
at System.String.GetStringForStringBuilder(String value, Int32 startIndex, Int32 length, Int32 capacity)
at System.Text.StringBuilder.GetNewString(String currentString, Int32 requiredLength)
at System.Text.StringBuilder.Append(Char value)
at System.IO.StringWriter.Write(Char value)
at System.Xml.XmlTextWriter.InternalWriteEndElement(Boolean longFormat)
at System.Xml.XmlTextWriter.WriteFullEndElement()
at System.Xml.XmlElement.WriteTo(XmlWriter w)
at System.Xml.XmlElement.WriteContentTo(XmlWriter w)
at System.Xml.XmlElement.WriteTo(XmlWriter w)
at System.Xml.XmlElement.WriteContentTo(XmlWriter w)
at System.Xml.XmlElement.WriteTo(XmlWriter w)
at System.Xml.XmlDocument.WriteContentTo(XmlWriter xw)
at System.Xml.XmlDocument.WriteTo(XmlWriter w)
at System.Xml.XmlNode.get_OuterXml()
좀 이러한 코드 써서 :
HttpWriter writer = new HttpWriter(context.Response);
XmlTextWriter xmlWriter = new XmlTextWriter(writer);
xmlResponse.OwnerDocument.WriteTo(xmlWriter);
을하지만 문제가 HttpWriter의 생성자 내부에 있다는 것입니다! HttpContext는 HttpWriter를 Write 메서드에서 내부적으로 사용합니다.
리플렉션을 통해 HttpWriter를 만드는 경우를 제외하고는 작업 영역이 무엇입니까?
작은 니트에 직접 스트리밍 할 것이다, 그러나 우리는 (Response.Output)는 오늘 XmlWriter.Create를 사용한다. "올바른"종류의 XmlWriter를 만들고 TextWriter를 사용하면 이미 설정된 인코딩을 사용합니다. –