I want to load a serialized xml class in Soap Envelope. I am starting, so I am not filling in the insides, so it looks like this:
<Envelope xmlns="http://schemas.xmlsoap.org/soap/envelope/" />
I want it to look like this:
<Envelope xmlns="http://schemas.xmlsoap.org/soap/envelope/" ></Envelope>`
The class I wrote is as follows:
[System.SerializableAttribute()] [System.Xml.Serialization.XmlTypeAttribute(AnonymousType = true, Namespace = "http://schemas.xmlsoap.org/soap/envelope/")] [System.Xml.Serialization.XmlRootAttribute(Namespace = "http://schemas.xmlsoap.org/soap/envelope/",ElementName="Envelope", IsNullable = true)] public class TestXmlEnvelope { [System.Xml.Serialization.XmlElement(ElementName="Body", Namespace="http://schemas.xmlsoap.org/soap/envelope/")] public System.Collections.ArrayList Body = new System.Collections.ArrayList(); }
I use this as an example, as other people may want it in a separate element. I am sure it should be simple, but unfortunately I do not know a suitable keyword for this.
Thanks as always for your help.
[Edit] Error while trying to use this instruction
System.Xml.Serialization.XmlSerializer xmlout = new System.Xml.Serialization.XmlSerializer(typeof(TestXmlEnvelope)); System.IO.MemoryStream memOut = new System.IO.MemoryStream(); xmlout.Serialize(memOut, envelope, namespc); Microsoft.Web.Services.SoapEnvelope soapEnv = new Microsoft.Web.Services.SoapEnvelope(); soapEnv.Load(memOut);
This gives me the error "Root Element not found".
[Edit] I fixed the error, the problem was that after I serialized the object, I did not set memOut.Position = 0. However, I hope this question helps other people who want to do this.