Web サービスに配信してもらいたい XML は次のとおりです。
<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; }
}
名前タグの代わりに場所タグを含む場所文字列を取得するにはどうすればよいですか?
ティア、ジョージ