這裏是我想要的web服務的XML提供:如何序列化從C#ASP.NET 3.5中的webservice返回的對象列表?
<business>
<locations>
<location>location 1</location>
<location>location 2</location>
</locations>
</business>
然而,而是下面的被返回:
<business>
<locations>
<location>
<name>location 1</name>
</location>
<location>
<name>location 2</name>
</location>
</locations>
</business>
下面是使用的代碼:
[WebMethod, ScriptMethod(ResponseFormat = ResponseFormat.Xml)]
public Business GetBusiness()
{
var business = new Business();
business.Locations = new List<Location>();
business.Locations.Add(new Location { Name = "location 1" });
business.Locations.Add(new Location { Name = "location 2" });
return business;
}
[XmlType(TypeName = "business")]
public class Business
{
[XmlArray(ElementName = "locations")]
[XmlArrayItem(ElementName = "location")]
public List<Location> Locations { get; set; }
}
[XmlType(TypeName = "location")]
public class Location
{
[XmlElement(ElementName = "name")]
public string Name { get; set; }
}
如何獲得位置字符串包含位置標記而不是具有名稱標記?
TIA, 喬治
是的!這是我一直在尋找的技巧...... XmlText完美地工作,謝謝。 – 2012-08-11 20:54:03