XML Serialize and Deserialize Problem XML Structure

Posted by Ph.E on Stack Overflow See other posts from Stack Overflow or by Ph.E
Published on 2010-06-17T12:20:24Z Indexed on 2010/06/17 12:23 UTC
Read the original article Hit count: 489

Camarades,

I'm having the following problem. Caught a list Struct, Serialize (Valid W3C) and send to a WebService. In the WebService I receive, transform to a string, valid by the W3C and then Deserializer, but when I try to run it, always occurs error, saying that some objects were not closed.

Any help?

Sent Code:

#region ListToXML
    private XmlDocument ListToXMLDocument(object __Lista)
    {
        XmlDocument _ListToXMLDocument = new XmlDocument();

        try
        {
            XmlDocument _XMLDoc      = new XmlDocument();
            MemoryStream _StreamMem  = new MemoryStream();
            XmlSerializer _XMLSerial = new XmlSerializer(__Lista.GetType());

            StreamWriter _StreamWriter = new StreamWriter(_StreamMem, Encoding.UTF8);
            _XMLSerial.Serialize(_StreamWriter, __Lista);

            _StreamMem.Position = 0;
            _XMLDoc.Load(_StreamMem);
            if (_XMLDoc.ChildNodes.Count > 0)
                _ListToXMLDocument = _XMLDoc;
        }
        catch (Exception __Excp)
        {
            new uException(__Excp).GerarLogErro(CtNomeBiblioteca);
        }

        return _ListToXMLDocument;
    }
    #endregion

Receive Code:

    #region XMLDocumentToTypedList
    private List<T> XMLDocumentToTypedList<T>(string __XMLDocument)
    {
        List<T> _XMLDocumentToTypedList = new List<T>();

        try
        {
            XmlSerializer _XMLSerial = new XmlSerializer(typeof(List<T>));
            MemoryStream _MemStream  = new MemoryStream();

            StreamWriter _StreamWriter = new StreamWriter(_MemStream, Encoding.UTF8);
            _StreamWriter.Write(__XMLDocument);

            _MemStream.Position = 0;
            _XMLDocumentToTypedList = (List<T>)_XMLSerial.Deserialize(_MemStream);
            return _XMLDocumentToTypedList;
        }
        catch (Exception _Ex)
        {
            new uException(_Ex).GerarLogErro(CtNomeBiblioteca);
            throw _Ex;
        }
    }
    #endregion

© Stack Overflow or respective owner

Related posts about web-services

Related posts about xml-serialization