我在webservice重载了几个方法,
在客户端调用时,如果是调用没被重载的方法则正常,
调用重载的方法时,就会报出“发现不明确的匹配”的异常,
webservice代码:        [WebMethod(Description = @"根据SQL语句获取DataSet", MessageName = "GetDataSet1")]
        public DataSet GetDataSet(string userName, string pwd, string sql)
        {
            try
            {
                if (!ServerUser.CheckQueryUser(userName, pwd))
                    return null;                return GetDataSet(sql);
            }
            catch (Exception excep)
            {
                //throw new Exception("开启事务失败!" + excep.Message);
                return null;
            }
        }        [WebMethod(Description = @"根据SQL语句获取DataSet并指定首张表名", MessageName = "GetDataSet2")]
        public DataSet GetDataSet(string userName, string pwd, string sql, string dtName)
        {
            try
            {
                if (!ServerUser.CheckQueryUser(userName, pwd))
                    return null;                return GetDataSet(sql, dtName);
            }
            catch (Exception excep)
            {
                //throw new Exception("开启事务失败!" + excep.Message);
                return null;
            }
        }
客户端代码:            string methodName = "GetDataSet";
            MethodInfo method = WSType.GetMethod(methodName);WSType是已经获取好的webservice的指定类型,不为空,没有错。webservice里用了MessageName来区分重载,
那客户端这边应该怎么标识?
请教一下大家,谢谢了~~~

解决方案 »

  1.   

    为什么要用反射调用,直接调用远程webservice不行吗?
      

  2.   

    即使用发射,应该也没问题啊,你Invoke的时候,把参数定义好传进去
      

  3.   

    我是动态生成的webservice代理类,
    生成dll到本地反射的,
    直接远程调用是可以,只是这次试验了新的动态调用的方法而已~
      

  4.   


    还没进行到传递参数那一步,
    到 MethodInfo method = WSType.GetMethod(methodName);
    这一步就已经出现异常了,后边的代码是,
                object[] args = new object[3];
                args.SetValue("sdms", 0);
                args.SetValue("sdms", 1);
                args.SetValue(sql, 2);
                DataSet result = (DataSet)method.Invoke(WSInstance, args);还没执行到
      

  5.   

    你用这个试试
    WSType.GetMethods()
    然后遍历所有方法,跟变量methodName比较
      

  6.   

    GetMethod也可以搞定//调用重载1
     MethodInfo method =WSType.GetMethod(methodName,BindingFlags.Public | BindingFlags.Instance,
     null,
    new Type[]{typeof(string), typeof(string),typeof(string)},null);//调用重载2
     MethodInfo method =WSType.GetMethod(methodName,BindingFlags.Public | BindingFlags.Instance,
     null,
    new Type[]{typeof(string), typeof(string),typeof(string),typeof(string)},null);
      

  7.   

    看msdn上怎么反射重载方法的
    http://msdn.microsoft.com/zh-cn/library/5fed8f59(VS.95).aspx#Y2180
      

  8.   


          mInfo = typeof(Example).GetMethod("MethodA",
              BindingFlags.Public | BindingFlags.Instance,
              null,
              new Type[] { typeof(int), typeof(int) },
              null);问题已解决,
    非常感谢,都忘了查msdn,
    分不多,不好意思,呵呵~~~