这就是我的问题和要求.
//下面是我的一个类函数列表,即用户,我有10-15个类函数
public IEnumerable<Entity.User> User() { OpenStoredPorcedure("spDB"); DataSet d = ExecuteDataSet(); DataTable myDataTable = d.Tables[0]; var stList = new List<Entity.User>(); foreach (DaTarow dr in myDataTable.Rows) { Entity.User usr = new Entity.User() { FirstName = dr["first_name"].ToString() ?? null,LastName = dr["last_name"].ToString() ?? null }; stList.Add(usr); } return stList.AsEnumerable(); }
public IEnumerable fetchData(int id) { IEnumerable result1 = null; switch (id) { case 1: IEnumerable<Entity.User> result = User().AsEnumerable<Entity.User>().ToArray(); result1 = result; break; case 2: IEnumerable<Entity.Project> result = User().AsEnumerable<Entity.Project>().ToArray(); result1 = result; break; } return result1; }
请求错误
服务器遇到处理请求的错误.异常消息是’无法序列化类型的参数’System.Collections.Generic.List`1 [Entity User]'(对于操作’fetchData’,合同’isyncService’),因为它不是确切的类型’System.Collections.IEnumerable ‘在方法签名中并且不在已知类型集合中.要序列化参数,请使用类型将类型添加到已知类型集合中
现在我希望在WCF中我们调用这个函数并传递id,它将导致该实体类的json列表.
public List<Entity.User> fetchData() { return User().ToList(); }
解决方法
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。