【发布时间】:2010-12-15 11:27:23
【问题描述】:
我已经开始在 VS2005 中开发一个新的 Web 服务。只有一种方法:
[WebMethod]
[XmlInclude(typeof(Person))]
public PersonAction GetAction()
{
PersonAction action = new PersonAction();
return action;
}
其中PersonAction 类包含一个引用Person 类的字段
[Serializable]
public class PersonAction
{
private string actionName = "XAction";
private Person person1;
private Person person2;
public PersonAction()
{
this.person = new Person();
this.person.Name = "P1";
}
public string Name
{
get
{
return this.actionName;
}
}
[XmlElement(Type = typeof(Person))]
public Person Person1
{
get
{
return this.person1;
}
}
}
我已经构建它,运行它...但是 wsdl 它总是包含一个空标签 PersonAction ...没有可用的嵌入式类型定义,所以我在客户端总是得到 null。
XmlElement,XmlInclude,[Serializable]显然没有效果...
我确定我错过了什么。
肯定有人在过去遇到过这个问题并且知道解决方案。我真的很感激任何对 VS2005 (.NET 2.0) 有帮助的代码。
谢谢
【问题讨论】:
-
我可以看到,将所有私有字段都更改为公共后,它就可以工作了...但是为什么公共属性如果引用私有字段则不序列化?
标签: c# object web-services return