How to get webserver to return the specified XML content

Source: Internet
Author: User
Tags object end sql net reference string tostring trim

You can use it as a local class by creating a webserver proxy, but can you return the specified XML? For example, after checking the account number and password through the Checkpass service, return the list of permissions that the user has. How to achieve it?

The Web service supports all the basic data types that are supported in the common language runtime, including String,integer,long, and so on. Arrays of basic data types are supported in addition to simple basic data types.

However, it is more interesting to support user-defined class and struct bodies. Basically, any type that can be represented by an XSD pattern is an argument or return type that can be

Through one weeks of groping, solve this problem, and learn how to read and output XML documents, database operations, webserver creation and reference. The following is part of the source code for beginners To reference, the lack of this please correct me.

/*checklogin Service *

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 description of Checklogin

[WebService (Namespace = "http://localhost/")]
[WebServiceBinding (ConformsTo = wsiprofiles.basicprofile1_1)]
public class CheckLogin:System.Web.Services.WebService {

Public Checklogin () {

If you are using a design component, uncomment it to follow the line
InitializeComponent ();

[WebMethod (Description = "Login", EnableSession = True)]
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)
Account and password correct, back to account information
DataRow objdatarow = objdatatable.rows[0];
Objcheckuser.userid = objdatarow["userid"]. ToString (). Trim ();;
Objcheckuser.pass = objdatarow["Pass"]. ToString (). Trim ();
Objcheckuser.username = objdatarow["username"]. ToString (). Trim ();

Check if the Allow field is empty
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;//Returns the XML string for the menu list

return objcheckuser;


public class CheckUser
public bool logined;
public string UserID;
public string Pass;
public string Username;
public string allow;
public string menuxml;//An XML string that returns a menu list



/*checklogin Service End * *

Start of/*menulist class *

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 Summary description
    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");
                 writer = xmlwriter.create (writerstr, settings);

Writer. WriteStartDocument ();
Writer. WriteStartElement ("Dstreeroot");
Writer. WriteAttributeString ("text", "Backstage Management system-[" +userid+ "]");
Writer. WriteAttributeString ("Treeid", "0000");
Writer. WriteAttributeString ("Open", "true");


Writer. WriteEndElement ();
Writer. WriteEndDocument ();
if (writer!= null)
Writer. Close ();
BUF = Writerstr. ToString ();
BUF = buf. Replace (@ "encoding=" "utf-16" "" ", @" encoding= "" Utf-8 "" "),//when using StringWriter as XML output, XML is automatically" Utf-16 ", where the Replace method is used to handle the If there is a better way, please advise!


private void Readqxdmb (string sjdm)//method of generating an XML tree
DataTable mytable = Objdatatable.copy ();
Datarow[] FoundRows;
FoundRows = mytable. Select ("sjdm= '" + SJDM + "");
if (Foundrows.length > 0)
Write child nodes
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");
Working with subordinate nodes
READQXDMB ((String) foundrows[i]["Qxdm"]);
Writer. WriteEndElement ();
MyTable. Dispose ();


/*menulist End *

/* Reference started * *

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
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";


/* Quote End/*

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.