c writes webservice service reference instance sharing

  • 2020-05-27 07:02:35
  • OfStack

First, a new web service file is created.


public  SqlWhhWebService1()
        {
            InitializeComponent();
        }
        #region Component Designer generated code
        //Required by the Web Services Designer 
        private IContainer components = null;
        /// <summary>
        /// Required method for Designer support - do not modify
        /// the contents of this method with the code editor.
        /// </summary>
        private void InitializeComponent()
        {
        }
        /// <summary>
        /// Clean up any resources being used.
        /// </summary>
        protected override void Dispose(bool disposing)
        {
            if (disposing && components != null)
            {
                components.Dispose();
            }
            base.Dispose(disposing);
        }
        #endregion

Then I call the method in my sqlhelper class to realize the basic operation on the data, just like we call 1 in bll, but I expose the method I defined by [WebMethod] for external calls. The Description attribute in [WebMethod(Description=" add operation ")] annotates the effect on the method, and it is displayed on the weiservice page at the same time.


[WebMethod(Description=" Add operation ")]
        public ResultModel AddData(string sql, SqlParameter[] sp)
        {
            return WhhSqlHelper.Intersql(sql, sp);
        }
        /// <summary>
        ///  Perform update operation 
        /// </summary>
        /// <param name="sql"></param>
        /// <param name="sp"></param>
        /// <returns></returns>
         [WebMethod(Description = " Modify the operating ")]
        public ResultModel Updata(string sql,SqlParameter[] sp)
        {
            return WhhSqlHelper.UpdateSql(sql, sp);
        }
        [WebMethod(Description = " Query operation ")]
        public ResultModel selectSQL(string sql,SqlParameter[]sp)
        {
            return WhhSqlHelper.SingSelectSql(sql, sp);
        }
        [WebMethod(Description = " Delete operation ")]
        public ResultModel Delete(string sql,SqlParameter[] sp)
        {
            return WhhSqlHelper.DeleteSql(sql,sp);
        }
        [WebMethod(Description = " Is there an operation ")]
        public ResultModel IsExistent(string sql, SqlParameter[] sp)
        {
            return WhhSqlHelper.IsExistent(sql, sp);
        }

These are just web calls for basic data operations, but they can also be extracted for some common functions for web encapsulation, such as addition, deletion, change and lookup of different tables, which can be encapsulated into 1.

Where WhhSqlHelper is the sqlhelper class I wrote, ResultModel is the return entity Model of a data operation I wrote.


Related articles: