は、我々はいくつかのIHTTPハンドラを持っています。我々は2 valiables持っ : の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メソッドで使用します。
はworkarroundsは(反射によりHttpWriterの作成を除く)何をして存在していますか?
小NITに直接ストリーミングするだろうが、我々は今日XmlWriter.Create(Response.Output)を使用する必要があります。 「正しい」種類のXmlWriterを作成し、TextWriterを使用すると、すでに設定されているエンコーディングが使用されます。 –