当前位置:IT168首页 > 技术开发 > 概述
[收藏此页] [打印] [推荐] [评论]

结合ajax技术通过web服务实现dotnet非链式工厂模式

责任编辑:nancy作者:ITPUB论坛   2008-07-02   
文本Tag: 微软 sql

【IT168技术文档】

  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}
上一页
1
下一页
收藏到: 添加到“百度搜藏”添加到“QQ书签”添加到“Google书签”添加到“Yahoo收藏”添加到“和讯网摘”
【内容导航】
本文欢迎转载,转载请注明:转载自IT168 [ http://www.it168.com/ ]
本文链接:http://tech.it168.com/d/2008-07-02/200807020844347.shtml
技术开发相关文章  
  • 暂无
友情推介