/// <summary>
        /// Gets the envelope as string
        /// </summary>
        /// <returns></returns>
        public virtual string GetXML()
        {
            // first, serialize to string
            var sb = new StringBuilder();
            var xs = new XmlSerializer(typeof(Envelope));

            using (var sw = new StringWriter8(sb))
            {
                xs.Serialize(sw, this);
            }

            return(sb.ToString());
        }
        public void WriteXml(XmlWriter writer)
        {
            if (!string.IsNullOrEmpty(this.Id))
            {
                writer.WriteAttributeString("Id", Namespaces.WS_SEC_UTILITY, this.Id);
            }

            if (this.Contents != null)
            {
                var settings   = new XmlWriterSettings();
                var serializer = new XmlSerializer(this.Contents.GetType());
                settings.OmitXmlDeclaration = true;

                using (var stringWriter = new StringWriter8())
                    using (var xmlWriter = XmlWriter.Create(stringWriter, settings))
                    {
                        serializer.Serialize(xmlWriter, this.Contents);

                        writer.WriteRaw(stringWriter.ToString());
                    }
            }
        }