调用webService的一个例子(反射、传参)
2012-06-02 23:30
489 查看
【转】使用反射动态实例化一个类,出现未能加载文件或程序集
http://social.microsoft.com/Forums/zh-CN/295/thread/267f8e34-06be-4baa-a923-ed185271163c
反射方法调用时的一个错误:参数计数不匹配( parameter count mismatch )
http://www.cnblogs.com/binarytree/archive/2010/04/21/1717491.html
我的一个反射传参的例子
webService:
businessRule.Class1:
UI:
UI 传参:
txtFunctionName:100
txtQueryString: 309,33
通过 webservice调用,最终得到结果: 342
http://social.microsoft.com/Forums/zh-CN/295/thread/267f8e34-06be-4baa-a923-ed185271163c
反射方法调用时的一个错误:参数计数不匹配( parameter count mismatch )
http://www.cnblogs.com/binarytree/archive/2010/04/21/1717491.html
我的一个反射传参的例子
webService:
public object DoF(string sFunctionName,string sQueryString) { try { string sServerPath = Server.MapPath(""); //string sTmp = System.AppDomain.CurrentDomain.BaseDirectory; Assembly asm = Assembly.LoadFrom(sServerPath + @"\bin\BusinessRule.dll");//加载前面生成的程序集 //未能加载文件或程序集“file:///C:\Program Files\Common Files\Microsoft Shared\DevServer\10.0\bin\Debug\BusinessRule.dll”或它的某一个依赖项。系统找不到指定的文件。 Type t = asm.GetType("BusinessRule.Class1"); object[] param =null; if (!string.IsNullOrEmpty(sQueryString)) param = sQueryString.Split(','); object o = Activator.CreateInstance(t); MethodInfo method = t.GetMethod("F" + sFunctionName); param = new object[] { param }; var result = method.Invoke(o, param); return result; } catch (Exception ex) { //return ex.Message; return "未实现的函数:" + sFunctionName; } }
businessRule.Class1:
public static string F100(string[] _sQueryString) { if (_sQueryString!=null && _sQueryString.Length>0) { int sum = 0; foreach (string i in _sQueryString) { sum += int.Parse(i); } return sum.ToString(); } else { return ""; } }
UI:
private void button1_Click(object sender, EventArgs e) { BBB.MyService se = new BBB.MyService(); var result = se.DoF(txtFunctionName.Text.Trim(),txtQueryString.Text.Trim()); txtResult.Text = result.ToString(); }
UI 传参:
txtFunctionName:100
txtQueryString: 309,33
通过 webservice调用,最终得到结果: 342
相关文章推荐
- 一个在java运行时利用反射动态调用方法的例子
- 一个简单的用JS调用WebService的例子
- javascript 调用webservice的一个例子
- 通过反射调用COM组件的一个例子
- 动态调用一个类的简单例子(java反射)
- 一个简单的cxf框架调用webservice接口天气预报例子
- [导入]一个简单的用JS调用WebService的例子
- 一个简单调用webservice的例子
- 一个简单的调用脚本文件的例子
- 调用webservice例子代码
- jquery学习心得:一个很好的css和js函数调用的例子
- 基于CFX WebService做的一个简单的HelloWorld例子
- ABAP--一个极好的调用外部java程序的Search Help Exit的实例(RFC好例子)
- java用XFire开发调用webService例子
- 一个简单的使用SOAP协议调用Webservice实现
- Lea指令计算地址(用于四则混合运算),附上一个函数调用例子及其反汇编代码,很清楚
- Java中的反射机制(二) 一个利用反射进行对象拷贝的例子
- Android调用天气预报的WebService简单例子
- 一个反射的例子
- 说明JavaScript 函数间按值传参的一个例子