我在Google上搜索过,我创建了这段代码:
public partial class XtraForm_Main : DevExpress.XtraEditors.XtraForm
{
public XtraForm_Main()
{
InitializeComponent();
}
private void simpleButton_Import_Click(object sender, EventArgs e)
{
WebRequest request = WebRequest.Create("http://192.168.10.141:4004/Code/WcfService_REST_SuiviColis/WcfService_REST_SuiviColis/Service1.svc/ListOrdre");
WebResponse ws = request.GetResponse();
//Stream oStream = ws.GetResponseStream();
//StreamReader oReader = new StreamReader(oStream);
//string res = oReader.ReadToEnd();
XmlSerializer s = new XmlSerializer(typeof(Pers_Ordre_Local));
Pers_Ordre_Local photos = (Pers_Ordre_Local)s.Deserialize(ws.GetResponseStream());
}
}
[XmlRoot("ArrayOfPers_Ordre")]
public class Pers_Ordre_Local
{
[XmlElement("CodeClient")]
string _CodeClient;
public string CodeClient
{
get { return _CodeClient; }
set { _CodeClient = value; }
}
[XmlElement("CodeDest")]
string _CodeDest;
public string CodeDest
{
get { return _CodeDest; }
set { _CodeDest = value; }
}
[XmlElement("NoOrdre")]
string _NoOrdre;
public string NoOrdre
{
get { return _NoOrdre; }
set { _NoOrdre = value; }
}
[XmlElement("LeDate")]
string _LeDate;
public string LeDate
{
get { return _LeDate; }
set { _LeDate = value; }
}
[XmlElement("LeGPS")]
string _LeGPS;
public string LeGPS
{
get { return _LeGPS; }
set { _LeGPS = value; }
}
[XmlElement("LeStatut")]
string _LeStatut;
public string LeStatut
{
get { return _LeStatut; }
set { _LeStatut = value; }
}
[XmlElement("LeCamion")]
string _LeCamion;
public string LeCamion
{
get { return _LeCamion; }
set { _LeCamion = value; }
}
[XmlElement("LeOrdrePos")]
string _LeOrdrePos;
public string LeOrdrePos
{
get { return _LeOrdrePos; }
set { _LeOrdrePos = value; }
}
[XmlElement("LeOrdreTot")]
string _LeOrdreTot;
public string LeOrdreTot
{
get { return _LeOrdreTot; }
set { _LeOrdreTot = value; }
}
}
我收到错误:
XML Document(1,2)
出错
当我调试它时,我发现了错误:
<ArrayOfPers_Ordre xmlns="http://schemas.datacontract.org/2004/07/WcfService_REST_SuiviColis"
xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
但我不知道如何解决它。我该如何解析这个xml文档?
我已将我的课程改为此课程,但stil也遇到了同样的错误。
[Serializable, XmlRoot("ArrayOfPers_Ordre"), XmlType("ArrayOfPers_Ordre")]
public class ListOfOrdes
{
public ListOfOrdes()
{
oOrdre = new List<Pers_Ordre_Local>();
}
[XmlElement("Pers_Ordre")]
public List<Pers_Ordre_Local> oOrdre { get; set; }
}
[XmlType("Pers_Ordre")]
public class Pers_Ordre_Local
{
[XmlElement("CodeClient")]
string _CodeClient;
public string CodeClient
{
get { return _CodeClient; }
set { _CodeClient = value; }
}
[XmlElement("CodeDest")]
string _CodeDest;
public string CodeDest
{
get { return _CodeDest; }
set { _CodeDest = value; }
}
[XmlElement("NoOrdre")]
string _NoOrdre;
public string NoOrdre
{
get { return _NoOrdre; }
set { _NoOrdre = value; }
}
[XmlElement("LeDate")]
string _LeDate;
public string LeDate
{
get { return _LeDate; }
set { _LeDate = value; }
}
[XmlElement("LeGPS")]
string _LeGPS;
public string LeGPS
{
get { return _LeGPS; }
set { _LeGPS = value; }
}
[XmlElement("LeStatut")]
string _LeStatut;
public string LeStatut
{
get { return _LeStatut; }
set { _LeStatut = value; }
}
[XmlElement("LeCamion")]
string _LeCamion;
public string LeCamion
{
get { return _LeCamion; }
set { _LeCamion = value; }
}
[XmlElement("LeOrdrePos")]
string _LeOrdrePos;
public string LeOrdrePos
{
get { return _LeOrdrePos; }
set { _LeOrdrePos = value; }
}
[XmlElement("LeOrdreTot")]
string _LeOrdreTot;
public string LeOrdreTot
{
get { return _LeOrdreTot; }
set { _LeOrdreTot = value; }
}