|
|

通过创建WEBServer代理可以当作本地类使用,但能不能返回指定的XML呢?
比如通过checkpass服务检测帐号和密码之后要返回该用户拥有的权限列表。怎么实现呢?
研究中........
请各大侠指点
asp_net高级编程928页19.4.2 数据类型
ASP.NET Web服务支持在公共语言运行时中支持的所有基本数据类型,包括String,integer,Long等等。除了简单的基本数据类型之外,还支持基本数据类型的数组。
但是,更有趣的是支持用户定义的类和结构体。基本上,任何可由XSD模式代表的类型都是可以作为ASP.NET的参数或返回类型。
asp_net 高级编程946页 19.7.1控制并整理xml
通过一个星期的摸索,解决了这个问题,并学习了如何读取和输出XML文档;数据库操作;WebServer的创建和引用。下面就部分源码供初学习者参考,不足之此请指正。- /*CheckLogin服务*/
- 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;
- ///
- /// CheckLogin 的摘要说明
- ///
- [WebService(Namespace = "http://localhost/")]
- [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
- public class CheckLogin : System.Web.Services.WebService {
- public CheckLogin () {
- //如果使用设计的组件,请取消注释以下行
- //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)
- {
- //帐号和密码正确,反回帐号信息
- 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服务结束*/
复制代码 |
|