XmlSerializer를 사용하여 목록에 wcf 웹 서비스의이 xml 응답을 역 직렬화하려고하지만 예외 메시지와 함께 실패합니다. XML 문서에 오류가 있습니다 (1, 2).
xml :
<ArrayOfNote xmlns="http://schemas.datacontract.org/2004/07/NotebookService" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
<Note>
<Author>Redouane</Author>
<Body>Test note</Body>
<CreationDate>2014-01-28T00:00:00</CreationDate>
<Id>1</Id>
<Title>Hello World</Title>
</Note>
</ArrayOfNote>
씨#:
public class Note
{
public int Id { get; set; }
public string Title { get; set; }
public System.DateTime CreationDate { get; set; }
public string Author { get; set; }
public string Body { get; set; }
}
그리고 이것은 수신 된 스트림을 역 직렬화하기 위해 작성한 코드입니다.
private HttpClient client = new HttpClient();
private List<Note> notes = new List<Note>();
. . .
XmlSerializer serializer = new XmlSerializer(typeof(List<Note>));
var responseData = await response.Content.ReadAsStreamAsync();
List<Note> list = serializer.Deserialize(responseData) as List<Note>;
도와주세요!
serializer 생성을 다음과 같이 변경하면 작동합니다.
XmlSerializer serializer = new XmlSerializer(typeof(List<Note>),
new XmlRootAttribute("ArrayOfNote") {
Namespace = "http://schemas.datacontract.org/2004/07/NotebookService"
});
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다