1.為web服務其他一致的進入點:int Execute(DataSet ds );
2.實現非鏈式原廠模式.動態載入服務提供者,從而提供服務.
1 public static int Execute(DataSet ds ){
2
3 string[] arr = UnPack(ds);
4
5 //Analysis and Invoke right method
6 string methodName = arr[0].ToString().Trim();
7 Object[] parme = new object[]{
8 System.Int32.Parse(arr[1].ToString().Trim()),
9 System.Int32.Parse(arr[2].ToString().Trim())
10 };
11
12 Assembly oAssembly = null;
13 Type oType = null;
14
15
16 oAssembly = Assembly.GetExecutingAssembly();
17 oType = oAssembly.GetType(methodName);
18
19 mycompute com = null;
20 com = (mycompute)Activator.CreateInstance(oType);
21 //oMethod = oType.GetMethod("Execute");
22
23 //int result = (int)oMethod.Invoke(new object(), parme);
24 int result = com.Execute(System.Int32.Parse(arr[1].ToString().Trim()),System.Int32.Parse(arr[2].Trim()));
25 return result;
26 }
27
28 public static string[] UnPack(DataSet ds)
29 {
30 if (ds == null) throw new Exception("DataSet Error ");
31
32 string[] arr = new string[3];
33
34 int i = 0 ;
35
36 foreach (DataRow row in ds.Tables[0].Rows)
37 {
38 foreach (DataColumn column in ds.Tables[0].Columns)
39 {
40 arr[i] = row[column].ToString();
41 i++;
42 }
43 }
44 return arr;
45 }
46
3.用戶端通過ajax獲得服務結果,實現無重新整理.
[Ajax.AjaxMethod()]
public int getResult(string methodName,string str1, string str2)
4.
1function serverside()
2{
3 _Default.getResult(
4 document.getElementById("Select1").value,
5 document.getElementById("Text1").value,
6 document.getElementById("Text2").value,ServerSide_CallBack);
7}
8
9function ServerSide_CallBack(res){
10// document.getElementById("result").value=response.value;
11 if(res.error!=null)alert(res.error);
12
13 document.getElementById("result").innerHTML="<font size=3 color=red>"+res.value+"</font>";
14
15}