using System.Xml.Serialization;
public static void Main()
var cc = new CreateContact
Email = "stest@gmail.com",
var xsn = new XmlSerializerNamespaces();
xsn.Add("a", "http://foo.co.uk/Contact");
var xs = new XmlSerializer(typeof (CreateContact));
using (var stringWriter = new StringWriter())
xs.Serialize(stringWriter, cc, xsn);
Console.WriteLine(stringWriter.ToString());
[XmlRoot(ElementName = "CreateContact", Namespace = "http://foo.co.uk")]
public class CreateContact
[XmlElement(ElementName = "contact")]
public Contact Contact { get; set; }
[XmlRoot("contact", Namespace = "http://foo.co.uk/Contact")]
public string Email { get; set; }
public string Firstname { get; set; }
public string Lastname { get; set; }
public string Phone { get; set; }
public string Title { get; set; }