zoukankan      html  css  js  c++  java
  • 解决Webservice内存溢出-用XmlWriter

    XmlWriter 表示一个编写器,该编写器提供一种快速、非缓存和只进的方式来生成包含 XML 数据的流或文件。这个就可以不占用内存,将数据放入磁盘中。也就不会出现内存溢出
    
    public class FileExercise : System.Web.Services.WebService { [WebMethod] public void HelloWorld() { // 生成临时文件 string tFName = System.IO.Path.GetTempFileName();//@"C:ResponseStream.txt" System.IO.FileStream stream = System.IO.File.Open(tFName, System.IO.FileMode.OpenOrCreate, System.IO.FileAccess.ReadWrite); XmlWriter writer = XmlWriter.Create(stream); writer.WriteStartDocument(); writer.WriteRaw("<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">"); writer.WriteRaw("<soap:Body>"); writer.WriteStartElement(MethodInfo.GetCurrentMethod().Name + "Response", @"http://tempuri.org/"); writer.Flush(); // 返回的主体 writer.WriteString("Hello word!"); // 将内存缓冲数据写进磁盘 ,当数据量大的时候分批处理并及时写入磁盘,可以降低内存压力 writer.Flush(); writer.WriteEndElement(); writer.WriteRaw("</soap:Body>"); writer.WriteRaw("</soap:Envelope>"); writer.WriteEndDocument(); writer.Flush(); writer.Close(); stream.Close(); HttpContext context = HttpContext.Current; //context.Response.ContentType = "application/soap+xml; charset=utf-8"; context.Response.WriteFile(tFName); return; } } }
  • 相关阅读:
    SpringCloud就是分布式啊?!?!?!
    有没有可能让运算符作为函数参数?
    【问题】用C++结构体实现顺序表,数据超过数组长度后,表长自动+1
    数学模型与数据结构的丝连
    最浅显易懂的数据库索引讲解
    whois 信息
    旁站C段查询
    网络搜索引擎
    服务指纹识别
    绕过CDN查找ip方法总结
  • 原文地址:https://www.cnblogs.com/honghong75042/p/3181515.html
Copyright © 2011-2022 走看看