How to make WebServer return the specified XML content

Source: Internet
Author: User
A WEBServer proxy can be created as a local application, but can I return the specified XML? For example, after checking the account and password through the checkpass service, you must return the list of permissions owned by the user. How can this problem be achieved? ASP. NETWeb service supports

A WEBServer proxy can be created as a local application, but can I return the specified XML? For example, after checking the account and password through the checkpass service, you must return the list of permissions owned by the user. How can this problem be achieved?


ASP. NET Web services support all basic data types supported during the runtime of public languages, including String, integer, and Long. In addition to simple basic data types, it also supports arrays of basic data types.


However, it is more interesting to support user-defined classes and Struct. Any types that can be represented by the XSD mode can be used as ASP. NET parameters or return types.


After a week of exploration, I solved this title and learned how to read and output XML documents, database control, and WebServer creation and reference. The following are some source code for the reference of beginners. if this is not enough, 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 of CheckLogin
///
[WebService (Namespace = "http: // localhost/")]
[WebServiceBinding (ConformsTo = WsiProfiles. BasicProfile1_1)]
Public class CheckLogin: System. Web. Services. WebService {

Public CheckLogin (){

// If the application design component is used, uncomment the following line.
// InitializeComponent ();
}

// [WebMethod (Description = "Login", EnableSession = true)]
[WebMethod]
Public checkuser Login (string sUserCode, string sPassword)
{
Checkuser objcheckuser = new checkuser ();
String sCheckLogin = ConfigurationManager. receivettings ["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.exe cuteDataSet (ref objCommand). Tables [0];
Objcheckuser. logined = (objDataTable. Rows. Count> 0 );
If (objcheckuser. logined)
{
// The account and password are accurate, and the account information is reversed
DataRow objDataRow = objDataTable. Rows [0];
Objcheckuser. userid = objDataRow ["UserID"]. ToString (). Trim ();;
Objcheckuser. pass = objDataRow ["Pass"]. ToString (). Trim ();
Objcheckuser. username = objDataRow ["UserName"]. ToString (). Trim ();

// Check whether 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; // return the XML string of 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; // return the XML string of the menu list

}

}

/* The CheckLogin service ends */

 

/* Start of the 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
{
///


/// Summary of 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.exe cuteDataSet (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", "background governance system-[" userid "]");

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: info-contact@alibabacloud.com 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.