日韩天天综合网_野战两个奶头被亲到高潮_亚洲日韩欧美精品综合_av女人天堂污污污_视频一区**字幕无弹窗_国产亚洲欧美小视频_国内性爱精品在线免费视频_国产一级电影在线播放_日韩欧美内地福利_亚洲一二三不卡片区

如何讓W(xué)ebServer返回指定XML內(nèi)容_Xml教程

編輯Tag賺U幣
教程Tag:暫無(wú)Tag,歡迎添加,賺取U幣!

推薦:XML編程實(shí)例:用ASP XML打造留言本
一、讀者指引 讀者指引幫助你掌握本文的梗概。以免你看了大半才明白這編文章不適合你,給你造成視覺(jué)污染。 如果你正在用ASP XML寫一些程序,或者你正在學(xué)XML那就值得一看。 閱讀本文須具

  通過(guò)創(chuàng)建WEBServer代理可以當(dāng)作本地類使用,但能不能返回指定的XML呢?比如通過(guò)checkpass服務(wù)檢測(cè)帳號(hào)和密碼之后要返回該用戶擁有的權(quán)限列表。怎么實(shí)現(xiàn)呢?


  ASP.NET Web服務(wù)支持在公共語(yǔ)言運(yùn)行時(shí)中支持的所有基本數(shù)據(jù)類型,包括String,integer,Long等等。除了簡(jiǎn)單的基本數(shù)據(jù)類型之外,還支持基本數(shù)據(jù)類型的數(shù)組。


  但是,更有趣的是支持用戶定義的類和結(jié)構(gòu)體。基本上,任何可由XSD模式代表的類型都是可以作為ASP.NET的參數(shù)或返回類型。


  通過(guò)一個(gè)星期的摸索,解決了這個(gè)問(wèn)題,并學(xué)習(xí)了如何讀取和輸出XML文檔;數(shù)據(jù)庫(kù)操作;WebServer的創(chuàng)建和引用。下面就部分源碼供初學(xué)習(xí)者參考,不足之此請(qǐng)指正。


/*CheckLogin服務(wù)*/

using System;
using System.Web;
using System.Collections;
using System.Web.Services;
using System.Web.Services.Protocols;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using mysql.SQL;
using myfunc.Common;


/// <summary>
/// CheckLogin 的摘要說(shuō)明
/// </summary>
[WebService(Namespace = "http://localhost/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
public class CheckLogin : System.Web.Services.WebService {

public CheckLogin () {

//如果使用設(shè)計(jì)的組件,請(qǐng)取消注釋以下行
//InitializeComponent();
}

//[WebMethod(Description = "Login", EnableSession = true)]
[WebMethod]
public checkuser Login(string sUserCode, string sPassword)
{
checkuser objcheckuser= new checkuser();
string sCheckLogin = ConfigurationManager.AppSettings["strCheckLogin"];
SqlShell objShell = new SqlShell();
SqlCommand objCommand = new SqlCommand(sCheckLogin);
objCommand.CommandType = CommandType.Text;
objCommand.Parameters.AddWithValue("@sUserCode", sUserCode);
objCommand.Parameters.AddWithValue("@sPassword", sPassword);
DataTable objDataTable = objShell.executeDataSet(ref objCommand).Tables[0];
objcheckuser.logined = (objDataTable.Rows.Count > 0);
if (objcheckuser.logined)
{
//帳號(hào)和密碼正確,反回帳號(hào)信息
DataRow objDataRow = objDataTable.Rows[0];
objcheckuser.userid = objDataRow["UserID"].ToString().Trim(); ;
objcheckuser.pass = objDataRow["Pass"].ToString().Trim();
objcheckuser.username = objDataRow["UserName"].ToString().Trim();

//檢查Allow字段是否為空
if (objDataRow.IsNull("Allow")) { objcheckuser.allow = ""; }
else { objcheckuser.allow = objDataRow["Allow"].ToString().Trim(); }

menulist objmenulist = new menulist(objDataRow["UserID"].ToString().Trim());
objcheckuser.menuxml = objmenulist.buf;//返回菜單列表的XML字符串

}
return objcheckuser;

}

public class checkuser
{
public bool logined;
public string userid;
public string pass;
public string username;
public string allow;
public string menuxml;//返回菜單列表的XML字符串

}

}

/*CheckLogin服務(wù)結(jié)束*/

/*menulist 類開(kāi)始*/

using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Xml;
using Singcn.SQL;
using System.Data.SqlClient;
using System.IO;
using System.Text;

namespace myfunc.Common
{
/// <summary>
/// PubFunc 的摘要說(shuō)明
/// </summary>
public class menulist
{
public XmlWriterSettings settings = new XmlWriterSettings();
public XmlWriter writer = null;
public string buf = "";
public SqlShell objShell;
public SqlCommand objCommand;
public DataTable objDataTable;

public menulist(string userid)
{
objShell = new SqlShell();
objCommand = new SqlCommand("select * from qxdmb order by jb,px,qxdm");
objCommand.CommandType = CommandType.Text;
objDataTable = objShell.executeDataSet(ref objCommand).Tables[0];

StringWriter writerstr = new StringWriter();
settings.Indent = true;
settings.Encoding = Encoding.GetEncoding("utf-8");
try
{
writer = XmlWriter.Create(writerstr, settings);

writer.WriteStartDocument();
writer.WriteStartElement("DSTreeRoot");
writer.WriteAttributeString("text", "后臺(tái)管理系統(tǒng)-[" userid "]");
writer.WriteAttributeString("treeId", "0000");
writer.WriteAttributeString("open", "true");


readqxdmb("0");

writer.WriteEndElement();
writer.WriteEndDocument();
}
finally
{
if (writer != null)
writer.Close();
}
buf = writerstr.ToString();
buf = buf.Replace(@"encoding=""utf-16""", @"encoding=""utf-8""");//在使用StringWriter 作為xml輸出時(shí)XML自動(dòng)為“utf-16”,此處用Replace方法處理,如有更好的方法請(qǐng)指教!

}

private void readqxdmb(string sjdm)//生成XML樹的方法
{
DataTable mytable = objDataTable.Copy();
DataRow[] foundRows;
foundRows = mytable.Select("sjdm='" sjdm "'");
if (foundRows.Length > 0)
{
//寫子節(jié)點(diǎn)
for (int i = 0; i < foundRows.Length; i )
{
writer.WriteStartElement("DSTree");
writer.WriteAttributeString("text", foundRows[i]["qxsm"].ToString().Trim());
writer.WriteAttributeString("treeId", foundRows[i]["qxdm"].ToString().Trim());
writer.WriteAttributeString("open", "false");
//處理下級(jí)節(jié)點(diǎn)
readqxdmb((string)foundRows[i]["qxdm"]);
writer.WriteEndElement();
}
}
mytable.Dispose();
}

}
}


/*menulist 結(jié)束*/

/*引用開(kāi)始 */

using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using localhost;

public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{

}

protected void Button1_Click(object sender, EventArgs e)
{
CheckLogin objCheckLogin=new CheckLogin();
CheckLogin.checkuser objcheckuser = new CheckLogin.checkuser();
objcheckuser=objCheckLogin.Login(TextBox1.Text, TextBox2.Text);
if (objcheckuser.logined) Label1.Text = objcheckuser.userid;
else Label1.Text = "false";

}
}


/*引用結(jié)束*/

分享:一個(gè)Asp與XML交互的實(shí)例源碼
XML 是標(biāo)準(zhǔn)擴(kuò)展語(yǔ)言,是未來(lái)Web編程的標(biāo)準(zhǔn),asp 是現(xiàn)在廣為流傳的web編程語(yǔ)言之一,能不能讓他們兩個(gè)聯(lián)合起來(lái)發(fā)揮作用呢?豆腐在這里給大家提供一個(gè)很簡(jiǎn)單的例子關(guān)于XML和XSL限于篇幅和知識(shí)水平豆

來(lái)源:模板無(wú)憂//所屬分類:Xml教程/更新時(shí)間:2008-08-22
相關(guān)Xml教程