For those that like to resolve problems, here's a big one :P
Well, I am developing a system using web services, where I send and receive XML as parameter (not normal parameters as Int, String, bool, etc).
After I receive a XML, I validate the XML with the XSD and also I convert that to an object.. after the process I also convert that object to an XML (validated by XSD) and return as answer of my request of the WS.
Well, my problem: I have complexType that I need to convert it using reflection, but, I am getting problem that I've never saw before.
My XSD is:
<xsd:element name="EnviarLoteRpsResposta">
<xsd:complexType>
<xsd:choice>
<xsd:sequence>
<xsd:element name="NumeroLote" type="tsNumeroLote" minOccurs="1" maxOccurs="1"/>
<xsd:element name="DataRecebimento" type="xsd:dateTime" minOccurs="1" maxOccurs="1"/>
<xsd:element name="Protocolo" type="tsNumeroProtocolo" minOccurs="1" maxOccurs="1"/>
</xsd:sequence>
<xsd:element ref="ListaMensagemRetorno" minOccurs="1" maxOccurs="1"/>
</xsd:choice>
</xsd:complexType>
</xsd:element>
My class (normal class with GETs and SETs):
[System.CodeDom.Compiler.GeneratedCodeAttribute("xsd", "2.0.50727.3038")]
[System.SerializableAttribute()]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Xml.Serialization.XmlTypeAttribute(AnonymousType = true, Namespace = "http://www.abrasf.org.br/ABRASF/arquivos/nfse.xsd")]
[System.Xml.Serialization.XmlRootAttribute(Namespace = "http://www.abrasf.org.br/ABRASF/arquivos/nfse.xsd", IsNullable = false)]
public class EnviarLoteRpsResposta
{
private object[] itemsField;
private ItemsChoiceType[] itemsElementNameField;
/// <remarks/>
[System.Xml.Serialization.XmlElementAttribute("DataRecebimento", typeof(System.DateTime))]
[System.Xml.Serialization.XmlElementAttribute("ListaMensagemRetorno", typeof(ListaMensagemRetorno))]
[System.Xml.Serialization.XmlElementAttribute("NumeroLote", typeof(string), DataType = "nonNegativeInteger")]
[System.Xml.Serialization.XmlElementAttribute("Protocolo", typeof(string))]
[System.Xml.Serialization.XmlChoiceIdentifierAttribute("ItemsElementName")]
public object[] Items
{
get
{
return this.itemsField;
}
set
{
this.itemsField = value;
}
}
/// <remarks/>
[System.Xml.Serialization.XmlElementAttribute("ItemsElementName")]
[System.Xml.Serialization.XmlIgnoreAttribute()]
public ItemsChoiceType[] ItemsElementName
{
get
{
return this.itemsElementNameField;
}
set
{
this.itemsElementNameField = value;
}
}
}
}
How am I using this class?:
EnviarLoteRpsResposta enviarLoteRpsResposta = new EnviarLoteRpsResposta();
enviarLoteRpsResposta.Items = new object[1];
enviarLoteRpsResposta.Items[0] = DateTime.Now;
enviarLoteRpsResposta.ItemsElementName = new ItemsChoiceType[1];
enviarLoteRpsResposta.ItemsElementName[0] = ItemsChoiceType.DataRecebimento;
My error happens when I try convert this object to a XML: XmlSerializer xs = new XmlSerializer(enviarLoteRpsResposta.GetType());
My error: There was an error reflecting type 'NFSEWS.Models.Bean.EnviarLoteRpsResposta'.
I don't know what do I can do to resolve this..