Q:

Keeping XML in Memory between Webservice Calls

First, I don't want to use a database or a local file. 
Is it possible to store variables in memory so they don't have to be created each time the webservice is called? The problem is that 
FullCompanyListCreateXML();

takes about 1 Minute to create the XDocument. So is there any way to prevent that the xml variable is dropped after the webservice call is finished?
    [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();
    }

Thanks,
Henrik

A:

2 ways:
1) You can add a global.asax class to the web service which will get created when the web application is first started, and will persist for as long as the worker process keeps it in memory. Override the 
2) create a static class to hold the values
See this blog entry, or this post on the topic of adding the global.asax class to web services. You can create things when the session starts, or when the application starts by overriding the Session_Start or Application_Start methods

