Dostosuj XML Serialize dzięki nowym tagom i atrybutom oraz rootowi

To jest mój typ:

public class MyObject {

    public string destAdd { get; set; }
    public long Time { get; set; }
    public int maxNumb { get; set; }
    public Account AccountCredentials { get; set; }

    public System.String Serialize() {
        String result = "";
        XmlSerializer xs = new XmlSerializer(typeof(MyObject));
        MemoryStream ms = new MemoryStream();
        xs.Serialize(ms, this);
        result = System.Text.Encoding.UTF8.GetString(ms.ToArray());
        ms.Close();
        ms.Dispose();
        xs = null;
        return result;
    }

    public static MyObject DeSerialize(String s) {
        MyObject result = new MyObject();
        XmlSerializer xs = new XmlSerializer(typeof(MyObject));
        MemoryStream ms = new MemoryStream(Encoding.UTF8.GetBytes(s));
        result = (MyObject)xs.Deserialize(ms);
        ms.Close();
        ms.Dispose();
        xs = null;
        return result;
    }
}

Następnie serializuję to tak:

        MyObject obj = new MyObject();
        obj.destAdd = "Destination";
        obj.maxNumb = 99;
        obj.Time = 128;
        obj.Account = new Account { username = "user", password = "pass" };
        string seializeObj = obj.Serialize();

Wynik to:

<?xml version="1.0"?>
<MyObject xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
  <destAdd>Destination</destAdd>
  <Time>128</Time>
  <maxNumb>99</maxNumb>
  <Account>
    <username>user</username>
    <password>pass</password>
  </Account>
</MyObject>

Ale potrzebuję następującego wyniku:

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:smag="http://targetaddress.com/">
  <soapenv:Header>
    <Account>
      <username>user</username>
      <password>pass</password>
    </Account>
  </soapenv:Header>
  <soapenv:Body>
    <smag:myobjinfos>
      <destAdd>Destination</destAdd>
      <Time>128</Time>
      <maxNumb>99</maxNumb>
    </smag:myobjinfos>
  </soapenv:Body>
</soapenv:Envelope>

Jak mogę zaimplementować serializację, aby uzyskać ten wynik? jakieś sugestie?

questionAnswers(1)

yourAnswerToTheQuestion