手机
当前位置:查字典教程网 >编程开发 >C#教程 >c#编写webservice服务引用实例分享
c#编写webservice服务引用实例分享
摘要:首先在新建了一个web服务文件。复制代码代码如下:publicSqlWhhWebService1(){InitializeComponent...

首先在新建了一个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.

【c#编写webservice服务引用实例分享】相关文章:

C# zxing二维码写入的实例代码

服务器端C#实现的CSS解析器

C# 一个WCF简单实例

C#编写的windows计算器的实例代码

gridview 显示图片的实例代码

c# 获得局域网主机列表实例

C#枚举数值与名称的转换实例分享

C# 观察者模式实例介绍

c#动态调用Webservice的两种方法实例

C#索引器简单实例代码

精品推荐
分类导航