<%@ WebService Language="C#" Class="CarData" %> using System; using System.Web; using System.Web.Caching; using System.Web.Services; using System.Web.Services.Protocols; using System.Xml; [WebService(Namespace = "http://tempuri.org/")] [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)] public class CarData : System.Web.Services.WebService { private const string CACHEENTRYNAME = "AjaxAspectsCars"; private const string DataFileName = "cardata.xml"; [WebMethod(Description = "Return Lookup entries that start with the given prefix.")] public string getModelsByClass(string carClass) { XmlDocument data = Load(); string ret = String.Empty; XmlNodeList xList = data.SelectNodes("/cardata/model[@title='" + carClass + "']/car"); for (int n = 0; n < xList.Count; n++) { ret += ((XmlElement)xList[n]).GetAttribute("type"); ret += ";"; } return(ret); } // getModelsByClass #region private methods /// <summary>Get the current List of Orte and load if necessary.</summary> private static XmlDocument Load() { Cache c = HttpRuntime.Cache; XmlDocument store = (XmlDocument)c[CACHEENTRYNAME]; if (store == null) { HttpContext ctx = HttpContext.Current; string fileName = ctx.Server.MapPath(DataFileName); System.Diagnostics.Trace.WriteLine("Load from File " + fileName); store = new XmlDocument(); store.Load(fileName); c.Insert(CACHEENTRYNAME, store, new CacheDependency(fileName), Cache.NoAbsoluteExpiration, TimeSpan.FromMinutes(2)); } // if return (store); } // Load #endregion }
This page is part of the http://www.mathertel.de/ web site.
For updates and discussions see http://ajaxaspects.blogspot.com/.