【C#伺服器開發】之Web Service
阿新 • • 發佈:2019-01-02
1 using System;
2 using System.Data;
3 using System.Configuration;
4 using System.Web;
5 using System.Web.Security;
6 using System.Web.UI;
7 using System.Web.UI.WebControls;
8 using System.Web.UI.WebControls.WebParts;
9 using System.Web.UI.HtmlControls;
10 public partial class _Default : System.Web.UI.Page
11 {
12 protectedvoid Page_Load(object sender, EventArgs e)
13 {
14 //在頁面載入的時候動態建立一個按鈕,在它的事件裡呼叫Webservice15 Button btn =new Button();
16 btn.Width =20;
17 btn.Text =" = ";
18 btn.Click +=new EventHandler(btn_Click);
19 E.Controls.Add(btn);
20 }
21 ///<summary>22 /// 定義動態建立Button的Click事件,在這個事件中呼叫Webservice
23 ///</summary>24 ///<param name="sender"></param>25 ///<param name="e"></param>26 void btn_Click(object sender, EventArgs e)
27 {
28 if (Num1.Text !=""&& Num2.Text !="")
29 {
30 //例項化引用的webservice物件31 localhost.Service WebserviceInstance =new localhost.Service();
32 int Oper = selectOper.SelectedIndex;
33 switch( Oper)
34 {
35 //通過例項化的webservice物件來呼叫Webservice暴露的方法36 case0:
37 Result.Text = WebserviceInstance.addition(double.Parse(Num1.Text), double.Parse(Num2.Text)).ToString();
38 break;
39 case1:
40 Result.Text = WebserviceInstance.subtract(double.Parse(Num1.Text), double.Parse(Num2.Text)).ToString();
41 break;
42 case2:
43 Result.Text = WebserviceInstance.multiplication(double.Parse(Num1.Text), double.Parse(Num2.Text)).ToString();
44 break;
45 case3:
46 Result.Text = WebserviceInstance.division(double.Parse(Num1.Text), double.Parse(Num2.Text)).ToString();
47 break;
48 }
49 }
50 }
51 }
52
2 using System.Data;
3 using System.Configuration;
4 using System.Web;
5 using System.Web.Security;
6 using System.Web.UI;
7 using System.Web.UI.WebControls;
8 using System.Web.UI.WebControls.WebParts;
9 using System.Web.UI.HtmlControls;
10 public partial class _Default : System.Web.UI.Page
12 protectedvoid Page_Load(object sender, EventArgs e)
13 {
14 //在頁面載入的時候動態建立一個按鈕,在它的事件裡呼叫Webservice15 Button btn =new Button();
16 btn.Width =20;
17 btn.Text =" = ";
18 btn.Click +=new EventHandler(btn_Click);
19 E.Controls.Add(btn);
20 }
21 ///<summary>22
23 ///</summary>24 ///<param name="sender"></param>25 ///<param name="e"></param>26 void btn_Click(object sender, EventArgs e)
27 {
28 if (Num1.Text !=""&& Num2.Text !="")
29 {
30 //例項化引用的webservice物件31 localhost.Service WebserviceInstance
32 int Oper = selectOper.SelectedIndex;
33 switch( Oper)
34 {
35 //通過例項化的webservice物件來呼叫Webservice暴露的方法36 case0:
37 Result.Text = WebserviceInstance.addition(double.Parse(Num1.Text), double.Parse(Num2.Text)).ToString();
38 break;
39 case1:
40 Result.Text = WebserviceInstance.subtract(double.Parse(Num1.Text), double.Parse(Num2.Text)).ToString();
41 break;
42 case2:
43 Result.Text = WebserviceInstance.multiplication(double.Parse(Num1.Text), double.Parse(Num2.Text)).ToString();
44 break;
45 case3:
46 Result.Text = WebserviceInstance.division(double.Parse(Num1.Text), double.Parse(Num2.Text)).ToString();
47 break;
48 }
49 }
50 }
51 }
52