当前位置:天才代写 > tutorial > 其他教程 > 如何才能让WebServer返回指定XML内容

如何才能让WebServer返回指定XML内容

2018-05-23 08:00 星期三 所属: 其他教程 浏览:412

 

获得知识的途径有很多,现在由小编为大家讲解有关语言编程的文章希望对大家有所帮助

 

c语言编程入门通过创建WEBServer代理可以当作本地类使用,但能不能返回指定的XML呢?比如通过checkpass服务检测帐号和密码之后要返回该用户拥有的权限列表。怎么实现呢?

  .NET Web服务支持在公共语言运行时中支持的所有基本数据类型,包括String,integer,Long等等。除了简单的基本数据类型之外,还支持基本数据类型的数组。

  但是,更有趣的是支持用户定义的类和结构体。基本上,任何可由XSD模式代表的类型都是可以作为ASP.NET的参数或返回类型。

  通过一个星期的摸索,解决了这个问题,并学习了如何读取和输出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 .SQL;
using myfunc.Common;

///
/// CheckLogin 的摘要说明
///
[WebService(Namespace = “http://localhost/”)][WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]public class CheckLogin : System.Web.Services.WebService {
    public CheckLogin () {
       C语言视频教程 //如果使用的组件,请取消注释以下行

我从事编程语言统计很多年了,有大量的数据来源包括代码存储库、Q&A讨论、招聘广告、社交媒体情况、教程页面访问、学习视频视图、开发者调查等等。数据发表在不同的时间,都可以被认为是精确的,
也可以被认为是有缺陷的,但是它们可以用于发现行业趋势。最后,不要期望一夜之间就变成一个编码忍者。有些人有一种天然的能力,但也是花了很多很多时间来磨练他们的技能,不断的学习新的技术和技巧。”

        //InitializeComponent();
    }
    //[WebMethod(Description = “Login”, EnableSession = true)]    [WebMethod]    public checkuser Login(string sUserCode, string sPass)
    {
        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服务结束*/
 
/*menulist 类开始*/
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
{
    ///
    /// PubFunc 的摘要说明
    ///
    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”, “后台管理系统-[“+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输出时XML自动为“utf-16”,此处用Replace方法处理,如有更好的方法请指教!
        }
        private void readqxdmb(string sjdm)//生成XML树的方法
        {
            DataTable mytable = objDataTable.Copy();
            DataRow[] foundRows;
            foundRows = mytable.Select(“sjdm='” + sjdm + “'”);
            if (foundRows.Length > 0)
            {C语言教程
                //写子节点
                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”);
                    //处理下级节点
                    readqxdmb((string)foundRows[i][“qxdm”]);
                    writer.WriteEndElement();
                }
            }
            mytable.Dispose();
        }
    }
}

/*menulist 结束*/
 
/*引用开始 */
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”;
    }
}

/*引用结束*/

文章很精彩,是否还想了解更多关于视频教程的文章,课课家官网是一个知识的海洋
 

    关键字:

天才代写-代写联系方式