加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

调用webService的一个例子(反射、传参)

发布时间:2020-12-17 00:58:00 所属栏目:安全 来源:网络整理
导读:【转】使用反射动态实例化一个类,出现未能加载文件或程序集 http://social.microsoft.com/Forums/zh-CN/295/thread/267f8e34-06be-4baa-a923-ed185271163c 反射方法调用时的一个错误:参数计数不匹配( parameter count mismatch ) http://www.cnblogs.com

【转】使用反射动态实例化一个类,出现未能加载文件或程序集

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 + @"binBusinessRule.dll");//加载前面生成的程序集
                
                //未能加载文件或程序集“file:///C:Program FilesCommon FilesMicrosoft SharedDevServer10.0binDebugBusinessRule.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

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读