using System;
using System.Web;
using System.Data.OleDb;
using System.Data;
using System.Xml;
public class Default : IHttpHandler
{
public void ProcessRequest(HttpContext context)
{
OleDbConnection c = new OleDbConnection (string.Format(@"rovider=Microsoft.Jet.OLEDB.4.0;Data Source=""{0}""ersist Security Info=***e", HttpContext.Current.Server.MapPath(@"~App_DataDatabase.mdb")));
var ds = new DataSet ();
c.Open();
//获取Url 中的max参数
var max = 0;
Int32.TryParse(HttpContext.Current.Request.QueryString["max"],out max);
//读取数据
new OleDbDataAdapter(string.Format("select{0} * from [User]", max > 0 ? " top " + max : string.Empty), c).Fill (ds);
c.Close();
//建立XML 文档
var xml = new XmlDocument ();
xml.LoadXml(ds.GetXml ());
//添加文档声明
xml.InsertBefore(xml.CreateXmlDeclaration("1.0", "UTF-8", null), xml.DocumentElement);
//添加xslt 声明
var xsl = xml.CreateProcessingIns***ction("xml- stylesheet", @"type=""text/xsl"" href=""Default.xslt""");
xml.InsertBefore(xsl, xml.DocumentElement);
//输出
context.Response.ContentType = "application/xml";
context.Response.Write(xml.InnerXml);
}
public bool IsReusable
{
get
{
return false;
}
}
}
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.Data.OleDb;
///
///WebService 的摘要说明
///
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
//若要允许使用 ASP.NET AJAX 从脚本中调用此 Web 服务,请取消对下行的注释。
// [System.Web.Script.Services.ScriptService]
public class WebService : System.Web.Services.WebService {
public WebService () {
//如果使用设计的组件,请取消注释以下行
//InitializeComponent();
}
[WebMethod(Description="添加一个新的用户名")]
public void AddName(string Name) {
OleDbConnection c = new OleDbConnection (string.Format(@"rovider=Microsoft.Jet.OLEDB.4.0;Data Source=""{0}""ersist Security Info=***e", HttpContext.Current.Server.MapPath(@"~App_DataDatabase.mdb")));
c.Open();
new OleDbCommand(string.Format("INSERT INTO [User] VALUES ('{0}','{1}')",Guid.NewGuid (),Name),c).ExecuteNonQuery ();
c.Close();
}
}