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

    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;
            }
        }
    }
  • 相关阅读:
    POJ1785 Binary Search Heap Construction
    Bzoj1185 [HNOI2007]最小矩形覆盖
    POJ2409 Let it Bead
    Bzoj2732 [HNOI2012]射箭
    Bzoj4515 [Sdoi2016]游戏
    Bzoj3925 [Zjoi2015]地震后的幻想乡
    Bzoj3223 Tyvj 1729 文艺平衡树
    COGS2642 / Bzoj4590 [Shoi2015]自动刷题机
    Bzoj1313 [HAOI2008]下落的圆盘
    python——描述符
  • 原文地址:https://www.cnblogs.com/honghong75042/p/5773946.html
Copyright © 2011-2022 走看看