webservice接口返回值为list的问题

GengWH 2014-12-04 02:58:42
写了一个webservice 的一个方法,该方法返回了一个list<PacsFeildsInfo>,PacsFeildsInfo 是一个可以序列化的类,里面有对应的包含get(),set()方法的属性。
客户端远程调用这个方法的时候list<PacsFeildsInfo> 结构接收到了,但是PacsFeildsInfo 里面的属性值都为null。各位大神帮忙看一下,为什么会这样。谢谢!
...全文
908 21 打赏 收藏 转发到动态 举报
写回复
用AI写文章
21 条回复
切换为时间正序
请发表友善的回复…
发表回复
tuoxie666 2015-10-19
  • 打赏
  • 举报
回复
在接口方法处声明序列化
如:
[WebMethod(Description = "测试用例")]
[XmlInclude(typeof(DeptModel))]
public List<DeptModel> WS_SFK_TESTEXP(int num)
{
List<DeptModel> res = new List<DeptModel>();
DeptModel deptModel = null;
for (int i = 0; i < num; i++)
{
deptModel = new DeptModel();
deptModel.DeptID = i + 1;
deptModel.EmployeeLM = new List<EmployeeModel>();

EmployeeModel employeeModel = null;
employeeModel = new EmployeeModel();
employeeModel.EmployeeID = 10000 + i + 1;
List<string> name = new List<string>();
name = GenerateChineseWords(3);
employeeModel.EmployeeName = name[0] + name[1] + name[2];
employeeModel.EmployeeTime = DateTime.UtcNow;
deptModel.EmployeeLM.Add(employeeModel);

employeeModel = new EmployeeModel();
employeeModel.EmployeeID = 10000 - i - 1;
List<string> name2 = new List<string>();
name2 = GenerateChineseWords(3);
employeeModel.EmployeeName = name2[0] + name2[1] + name2[2];
employeeModel.EmployeeTime = DateTime.Now;
deptModel.EmployeeLM.Add(employeeModel);

res.Add(deptModel);
}

return res;
}

同时,类的实体声名为可序列化的类
[Serializable]
public class DeptModel
{
private int deptID;

public int DeptID
{
get { return deptID; }
set { deptID = value; }
}
private List<EmployeeModel> employeeLM;

public List<EmployeeModel> EmployeeLM
{
get { return employeeLM; }
set { employeeLM = value; }
}

}

调试过程:


得到结果:
  • 打赏
  • 举报
回复
[DataContract] [DataMember]
  • 打赏
  • 举报
回复
[DataContract] [DataMember]
GengWH 2014-12-04
  • 打赏
  • 举报
回复
引用 15 楼 kongwei521 的回复:
引用 14 楼 GengWH 的回复:
哎,只能靠自己了。。
额 么看我发呢些地址吗?参考下。
参考了,都不行。实体类里的属性值还是null。。。无语了
GengWH 2014-12-04
  • 打赏
  • 举报
回复
引用 15 楼 kongwei521 的回复:
引用 14 楼 GengWH 的回复:
哎,只能靠自己了。。
额 么看我发呢些地址吗?参考下。
参考了,都不行。实体类里的属性值还是null。。。无语了
GengWH 2014-12-04
  • 打赏
  • 举报
回复
引用 15 楼 kongwei521 的回复:
引用 14 楼 GengWH 的回复:
哎,只能靠自己了。。
额 么看我发呢些地址吗?参考下。
参考了,都不行。实体类里的属性值还是null。。。无语了
蝶恋花雨 2014-12-04
  • 打赏
  • 举报
回复
引用 14 楼 GengWH 的回复:
哎,只能靠自己了。。
额 么看我发呢些地址吗?参考下。
GengWH 2014-12-04
  • 打赏
  • 举报
回复
哎,只能靠自己了。。
GengWH 2014-12-04
  • 打赏
  • 举报
回复
救命啊!!!!
GengWH 2014-12-04
  • 打赏
  • 举报
回复
怎么办呢?????
GengWH 2014-12-04
  • 打赏
  • 举报
回复
引用 8 楼 kongwei521 的回复:
get;set 属性是public 还是private?
public
蝶恋花雨 2014-12-04
  • 打赏
  • 举报
回复
get;set 属性是public 还是private?
GengWH 2014-12-04
  • 打赏
  • 举报
回复
救命啊!!!
GengWH 2014-12-04
  • 打赏
  • 举报
回复
引用 4 楼 hrabeyond 的回复:
既然可以序列化,为什么不用json来做
客户端是winform。。
GengWH 2014-12-04
  • 打赏
  • 举报
回复
引用 3 楼 stubble 的回复:
set的时候 是不是被清空了
没有,我在调试的时候,list里都有值,发布到服务器,客户端调用就都为null 了.. 是不是webservice不支持返回值为list的?
手抓宝 2014-12-04
  • 打赏
  • 举报
回复
既然可以序列化,为什么不用json来做
异常异长 2014-12-04
  • 打赏
  • 举报
回复
set的时候 是不是被清空了
GengWH 2014-12-04
  • 打赏
  • 举报
回复
大侠都去哪里了?
加载更多回复(1)

62,046

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧