Esempio n. 1
0
        /// <summary>
        /// Constructor clase Envelope.
        /// </summary>
        /// <param name="stream">Ruta al archivo xml que contiene el mensaje SOAP.</param>
        public Envelope(Stream stream)
        {
            Envelope envelope = null;

            XmlSerializer serializer = new XmlSerializer(this.GetType());

            using (StreamReader r = new StreamReader(stream))
                envelope = serializer.Deserialize(r) as Envelope;

            if (envelope == null)
            {
                throw new Exception("XML SOAP selerailization error");
            }

            Header = envelope.Header;
            Body   = envelope.Body;

            SIIParser.ClearNulls(Body);
        }
Esempio n. 2
0
        /// <summary>
        /// Devuelve una cadena con el envelope representado
        /// en xml en formato binario con codificaión UTF8.
        /// </summary>
        /// <returns>Envelope en xml en binario con codificaión UTF8.</returns>
        public byte[] ToArray(SIINamespaces ns = SIINamespaces.siiLR, SIINamespaces nsSum = SIINamespaces.sii)
        {
            byte[] result = null;

            SIIParser.ClearNulls(this); // Limpia nulos

            XmlSerializer           xmlSerializer = new XmlSerializer(GetType());
            XmlSerializerNamespaces namespaces    = new XmlSerializerNamespaces();

            namespaces.Add("soapenv", "http://schemas.xmlsoap.org/soap/envelope/");
            namespaces.Add(ns.ToString(), SIIParser.Namespaces[ns]);
            namespaces.Add(nsSum.ToString(), SIIParser.Namespaces[nsSum]);

            var ms = new MemoryStream();

            using (StreamWriter sw = new StreamWriter(ms, Encoding.GetEncoding("UTF-8")))
            {
                xmlSerializer.Serialize(sw, this, namespaces);
                result = ms.ToArray();
            }

            return(result);
        }
Esempio n. 3
0
        /// <summary>
        /// Constructor clase Envelope.
        /// </summary>
        /// <param name="xmlPath">Ruta al archivo xml que contiene el mensaje SOAP.</param>
        public Envelope(string xmlPath)
        {
            Envelope envelope = null;

            XmlSerializer serializer = new XmlSerializer(this.GetType());

            if (File.Exists(xmlPath))
            {
                using (StreamReader r = new StreamReader(xmlPath))
                {
                    envelope = serializer.Deserialize(r) as Envelope;
                }
            }

            if (envelope == null)
            {
                throw new Exception("XML SOAP selerailization error");
            }

            Header = envelope.Header;
            Body   = envelope.Body;

            SIIParser.ClearNulls(Body);
        }