private static string SerializeModel(Model model) { var memoryStream = new MemoryStream(); var xmlWriter = new XmlTextWriter(new StreamWriter(memoryStream, Encoding.UTF8)) { Formatting = Formatting.None }; var namespaces = new XmlSerializerNamespaces(); namespaces.Add(String.Empty, String.Empty); var serializer = new XmlSerializer(model.GetType()); serializer.Serialize(xmlWriter, model, namespaces); memoryStream.Seek(0, SeekOrigin.Begin); using (var reader = new StreamReader(memoryStream, Encoding.UTF8)) { return reader.ReadToEnd(); } }
private void WriteBodyAsXml(Model model) { var xmlWriter = new XmlTextWriter(new StreamWriter(m_context.Request.Body, Encoding.UTF8)) { Formatting = Formatting.None }; var namespaces = new XmlSerializerNamespaces(); namespaces.Add(String.Empty, String.Empty); var serializer = new XmlSerializer(model.GetType()); serializer.Serialize(xmlWriter, model, namespaces); }