【发布时间】:2014-09-04 02:26:17
【问题描述】:
当尝试从来自WebService的XML文本中获取值时,如下图所示值为null。
代码
string texto =
"<?xml version=\"1.0\"?>" +
"<EnviarLoteRpsResposta xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\">"+
" <NumeroLote>3774</NumeroLote>" +
" <DataRecebimento>2014-09-03T23:03:57.3428675-03:00</DataRecebimento>" +
" <Protocolo>635453822373428675</Protocolo>" +
"</EnviarLoteRpsResposta>";
XmlRootAttribute rootAttribute = new XmlRootAttribute("EnviarLoteRpsResposta");
XmlSerializer serializer = new XmlSerializer(typeof(WS.NF.EnviarLoteRpsResposta), rootAttribute);
WS.NF.EnviarLoteRpsResposta ei = (WS.NF.EnviarLoteRpsResposta)serializer.Deserialize(new StringReader(texto));
返回变量ei
编辑
据我所见,返回不是ListaMensagemRetorno 字段。是这个问题吗?
服务参考
[System.CodeDom.Compiler.GeneratedCodeAttribute("System.Xml", "4.0.30319.33440")]
[System.SerializableAttribute()]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Xml.Serialization.XmlTypeAttribute(Namespace="http://www.e-governeapps2.com.br/")]
public partial class EnviarLoteRpsResposta {
private System.Nullable<ulong> numeroLoteField;
private System.Nullable<System.DateTime> dataRecebimentoField;
private string protocoloField;
private MensagemRetorno[] listaMensagemRetornoField;
/// <remarks/>
[System.Xml.Serialization.XmlElementAttribute(IsNullable=true)]
public System.Nullable<ulong> NumeroLote {
get {
return this.numeroLoteField;
}
set {
this.numeroLoteField = value;
}
}
/// <remarks/>
[System.Xml.Serialization.XmlElementAttribute(IsNullable=true)]
public System.Nullable<System.DateTime> DataRecebimento {
get {
return this.dataRecebimentoField;
}
set {
this.dataRecebimentoField = value;
}
}
/// <remarks/>
public string Protocolo {
get {
return this.protocoloField;
}
set {
this.protocoloField = value;
}
}
/// <remarks/>
public MensagemRetorno[] ListaMensagemRetorno {
get {
return this.listaMensagemRetornoField;
}
set {
this.listaMensagemRetornoField = value;
}
}
}
【问题讨论】:
-
你检查生成的xml文件是否包含所有数据
-
@Seminda XML 返回不存在
ListaMensagemRetorno