代码之家  ›  专栏  ›  技术社区  ›  Henrik P. Hessel

在Web服务调用之间将XML保留在内存中

  •  0
  • Henrik P. Hessel  · 技术社区  · 15 年前

    FullCompanyListCreateXML();
    

    创建XDocument大约需要1分钟。那么,有什么方法可以防止在webservice调用完成后删除xml变量呢?

        [WebMethod(CacheDuration = 120)]
        public String FullCooperationListChunkGet(int part, int chunksize)
        {
            StringBuilder output_xml = new StringBuilder();
            XDocument xml = FullCompanyListCreateXML();
            IEnumerable<XElement> xml_query = xml.Root.Elements("Cooperation").Skip(part * chunksize).Take(chunksize);
    
            foreach (XElement x in xml_query)
            {
                output_xml.Append(x.ToString());
            }
            output_xml.Insert(0, "<Cooperations>");
            output_xml.Append("</Cooperations>");
            return output_xml.ToString().Zip();
        }
    

    谢谢
    亨里克

    3 回复  |  直到 15 年前
        1
  •  1
  •   Ash    15 年前

    将xml写入实际指向 MemoryStream .

    然后用诸如 StreamReader

        2
  •  1
  •   Community CDub    9 年前

    2种方式:

    1) 您可以将global.asax类添加到web服务中,该类将在web应用程序首次启动时创建,并且只要工作进程将其保留在内存中,该类就会一直存在。覆盖

    看到这个了吗 blog entry this post 关于将global.asax类添加到web服务的主题。您可以在会话启动时创建内容,或者在应用程序启动时覆盖会话启动或应用程序启动方法

        3
  •  1
  •   Fredrik Mörk    15 年前

    你可以调查一下 using the built-in caching mechanism 在ASP.NET中。它很容易使用。