개체 목록을 deserialize하는 데 문제가 있습니다. 하나의 객체 만 객체로 직렬화 할 수는 있지만 목록을 가져올 수는 없습니다. 난 그냥 빈 목록을 반환 아무런 오류가 발생합니다.deserializing 문제 개체 목록
<locations>
<location locationtype="building" locationtypeid="1">
<id>1</id>
<name>Building Name</name>
<description>Description of Building</description>
</location>
</locations>
이것은 내가 가지고있는 클래스이며 나는 GetAll
방법으로 직렬화 복원하고 :이 시도
[Serializable()]
[XmlRoot("location")]
public class Building
{
private string method;
[XmlElement("id")]
public int LocationID { get; set; }
[XmlElement("name")]
public string Name { get; set; }
[XmlElement("description")]
public string Description { get; set; }
[XmlElement("mubuildingid")]
public string MUBuildingID { get; set; }
public List<Building> GetAll()
{
var listBuildings = new List<Building>();
var building = new Building();
var request = WebRequest.Create(method) as HttpWebRequest;
var response = request.GetResponse() as HttpWebResponse;
var streamReader = new StreamReader(response.GetResponseStream());
TextReader reader = streamReader;
var serializer = new XmlSerializer(typeof(List<Building>),
new XmlRootAttribute() { ElementName = "locations" });
listBuildings = (List<Building>)serializer.Deserialize(reader);
return listBuildings;
}
}
은 오류가 발생하고 있습니까? –
일련 번호가 표시되지 않는 목록은 무엇입니까? 'GetAll()'메소드 인 경우, 클래스 메소드를 호출하는 비즈니스에서 serializer가 (아마도 드물게는) 그런 것이 아니기 때문입니다. 그들은 물건의 재산 가치를 보존하는 사업에 종사하고 있습니다. – 48klocs
오류가 발생하지 않습니다. 단지 빈 목록 만 반환합니다. GetAll 메서드를 serialize하려면 노력하고있어, Get 메서드를 사용하여 webservice deserialize 및 해당 건물 개체 채우기. –