c#编写webservice服务引用实例分享

时间:2023-05-11 19:28:41 

首先在新建了一个web服务文件。


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

然后自己调用自己的sqlhelper类中的方法,实现对数据的基本操作,其实和我们在bll中的调用一样,只不过通过[WebMethod]把自己所定义的方法暴露出来供外部调用,[WebMethod(Description="添加操作")]中的Description属性标注了对改方法的作用,同时在weiservice页面中显示出来。


[WebMethod(Description="添加操作")]
        public ResultModel AddData(string sql, SqlParameter[] sp)
        {
            return WhhSqlHelper.Intersql(sql, sp);
        }
        /// <summary>
        /// 执行更新操作
        /// </summary>
        /// <param name="sql"></param>
        /// <param name="sp"></param>
        /// <returns></returns>
         [WebMethod(Description = "修改操作")]
        public ResultModel Updata(string sql,SqlParameter[] sp)
        {
            return WhhSqlHelper.UpdateSql(sql, sp);
        }
        [WebMethod(Description = "查询操作")]
        public ResultModel selectSQL(string sql,SqlParameter[]sp)
        {
            return WhhSqlHelper.SingSelectSql(sql, sp);
        }
        [WebMethod(Description = "删除操作")]
        public ResultModel Delete(string sql,SqlParameter[] sp)
        {
            return WhhSqlHelper.DeleteSql(sql,sp);
        }
        [WebMethod(Description = "是否存在操作")]
        public ResultModel IsExistent(string sql, SqlParameter[] sp)
        {
            return WhhSqlHelper.IsExistent(sql, sp);
        }

这些只是对基本的数据操作的web调用,还可以针对一些公共功能给提炼出来进行web封装,比如说,不同表的增删改查,这些都可以的把封装到一起。

其中的 WhhSqlHelper是我写的一个sqlhelper类,ResultModel是我写的一个数据操作的返回实体Model.

标签:webservice服务,编写webservice
0
投稿

猜你喜欢

  • SpringBoot返回多种格式的数据的实现示例

    2023-11-24 14:22:52
  • 处理java异步事件的阻塞和非阻塞方法分析

    2023-04-16 05:06:01
  • C#实现动态执行字符串脚本(优化版)的示例代码

    2022-06-10 19:13:54
  • java实现文件归档和还原

    2023-02-28 23:09:51
  • C#创建windows系统用户的方法

    2022-07-16 20:30:12
  • Java实现图形化界面的日历

    2023-03-04 04:07:47
  • C#/VB.NET实现HTML转为XML的示例代码

    2021-08-13 20:46:48
  • 解决Android studio3.6安装后gradle Download失败(构建不成功)

    2021-07-20 15:38:42
  • 使用Java实现qq邮箱发送邮件

    2023-10-14 18:24:36
  • java中的session对象及其常用方法小结

    2023-11-25 02:31:33
  • java中Servlet程序下载文件实例详解

    2022-04-28 18:26:10
  • c++与c#的时间转换示例分享

    2022-08-22 07:21:40
  • c# 如何更简单的使用Polly

    2022-10-24 11:27:46
  • Android获取手机文件夹及文件列表的方法

    2022-04-22 22:22:32
  • Java拦截器Interceptor和过滤器Filte的执行顺序和区别

    2022-06-01 20:37:11
  • mybatis 运行时加载自定义mapper文件方式

    2023-08-16 10:00:16
  • Java开发中为什么要使用单例模式详解

    2023-12-24 21:56:40
  • 快速解决commons-fileupload组件无法处理自定义head信息的bug

    2023-03-05 15:20:14
  • android中SQLite使用及特点

    2023-07-24 23:33:28
  • Android编程显示网络上的图片实例详解

    2021-11-29 05:21:10
  • asp之家 软件编程 m.aspxhome.com