当前位置: 代码迷 >> Web Service >> WebService与List解决方法
  详细解决方案

WebService与List解决方法

热度:590   发布时间:2016-05-02 03:11:00.0
WebService与List
在WebService定义一个List集合参数,为什么到了客户端引用的时候就成了一个数组呢?
错误 1 与“Eis.Portal.Isdk.IAccess.ExecuteDataTable(string, Eis.Portal.Isdk.CommandType, string, Eis.Portal.Isdk.ListPara[])”最匹配的重载方法具有一些无效参数 E:\Web\EIS\EisPortal\Default.aspx.cs 71 44 EisPortal
 
C# code
 private void LoadUser()        {            try            {                                          strSQL = "SELECT * FROM LoginUser where UserName like @UserName and password like @password";                IAccess access = new IAccess();                             List<ListPara> list = new List<ListPara>();                ListPara lp = new ListPara();                lp.para = "UserName";                lp.value = "A";                list.Add(lp);                lp.para = "Password";                lp.value = "123456";                list.Add(lp);                //list.Add(new ListPara("UserName", "A"));                //list.Add(new ListPara("Password", "123456"));                 System.Data.DataTable dt = access.ExecuteDataTable(guid, Eis.Portal.Isdk.CommandType.Text, strSQL,list);//List集合???                this.gvUser.DataSource = dt;                this.gvUser.DataBind();            }            catch (Exception ex)            {                throw ex;            }        }

WebService代码
C# code
namespace EIS.ISdk{    /// <summary>    /// IAceess 的摘要说明    /// </summary>    [WebService(Namespace = "http://eissdk.org/")]    [WebServiceBinding(ConformsTo = WsiProfiles.None)]    [System.ComponentModel.ToolboxItem(false)]    // 若要允许使用 ASP.NET AJAX 从脚本中调用此 Web 服务,请取消对下行的注释。    // [System.Web.Script.Services.ScriptService]    public class IAccess : System.Web.Services.WebService    {        [WebMethod(MessageName = "ExecuteDataTable", Description = "Return Execute Data Table")]        public DataTable ExecuteDataTable(string guid, CommandType cmdType, string cmdText)        {            if (LoginAuth.GuidAuth(guid))            {                List<ListPara> list = new List<ListPara>();                                list.Add(new ListPara("UserName", "A"));                list.Add(new ListPara("Password", "123456"));                 return SqlHelper.ExecuteDataTable(cmdType, cmdText, SqlHelper.GetParameters(list));            }            else            {                return null;            }        }        [WebMethod(MessageName = "ExecuteDataTable2", Description = "Return Execute Data Table")]        public DataTable ExecuteDataTable(string guid, CommandType cmdType, string cmdText,List<ListPara> list)        {            if (LoginAuth.GuidAuth(guid))            {                  return SqlHelper.ExecuteDataTable(cmdType, cmdText, SqlHelper.GetParameters(list));            }            else            {                return null;            }        }}


------解决方案--------------------
参数当然不匹配了,你看看你的WebService里ExecuteDataTable这2个重载的方法,及其内部使用的ExecuteDataTable方法,参数类型严重不匹配。

你仔细看看。
------解决方案--------------------
你用的自动生成代码所以他会变成Array
你将客户端的返回改成List<T> 返回值部份强制转换就可以了。比较郁闷的是每次必须改。

------解决方案--------------------
不能很好的利用系统的autoupdate功能。
我用的是spring.net做的代理,发布的服务继承一个接口,spring.net可以为我们动态生成一个webservice代理。
------解决方案--------------------
DataSet尽量不要考虑用,因为DataSet只在微软环境可以序列化反序列化。
  相关解决方案