c#編寫webservice服務引用實例分享
首先在新建了一個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>
/// 執(zhí)行更新操作
/// </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#使用HttpPost請求調用WebService的方法
- .NET C#創(chuàng)建WebService服務簡單實例
- C# 創(chuàng)建、部署和調用WebService簡單示例
- C# WebService發(fā)布以及IIS發(fā)布
- C# 調用 JavaWebservice服務遇到的問題匯總
- C#調用WebService實例開發(fā)
- C#動態(tài)webservice調用接口
- C#使用WebService結合jQuery實現無刷新翻頁的方法
- c#動態(tài)改變webservice的url訪問地址
- c#動態(tài)調用Webservice的兩種方法實例
- C#創(chuàng)建、部署、調用WebService圖文實例詳解

