2 // SoapEnvelope.cs: Soap Envelope
5 // Sebastien Pouliot (spouliot@motus.com)
7 // (C) 2002, 2003 Motus Technologies Inc. (http://www.motus.com)
15 namespace Microsoft.Web.Services {
17 public class SoapEnvelope : XmlDocument {
19 private SoapContext context;
20 private XmlElement envelope;
21 private XmlElement body;
22 private XmlElement header;
24 private Encoding _encoding;
27 public SoapEnvelope ()
29 envelope = CreateElement (Soap.Prefix, Soap.ElementNames.Envelope, Soap.NamespaceURI);
30 AppendChild (envelope);
33 internal SoapEnvelope (SoapContext context) : this ()
35 this.context = context;
39 public Encoding Encoding {
41 if(_encoding == null) {
42 return new UTF8Encoding (false);
48 if(_encoding is UTF8Encoding) {
49 _encoding = new UTF8Encoding (false);
55 public XmlElement Body {
58 XmlNodeList xnl = GetElementsByTagName (Soap.ElementNames.Body, Soap.NamespaceURI);
59 body = (XmlElement)xnl[0];
65 public SoapContext Context {
68 context = new SoapContext (this);
73 public XmlElement Envelope {
74 get { return envelope; }
77 public XmlElement Header {
80 XmlNodeList xnl = GetElementsByTagName (Soap.ElementNames.Header, Soap.NamespaceURI);
81 header = (XmlElement)xnl[0];
87 public XmlElement CreateBody ()
90 body = CreateElement (Soap.Prefix, Soap.ElementNames.Body, Soap.NamespaceURI);
91 DocumentElement.AppendChild (body);
96 public XmlElement CreateHeader ()
99 header = CreateElement (Soap.Prefix, Soap.ElementNames.Header, Soap.NamespaceURI);
100 // be sure Header comes before the Body
101 DocumentElement.PrependChild (header);
106 private void InvalidateCache ()
108 envelope = DocumentElement;
113 public override void Load (Stream stream)
119 public override void Load (string filename)
121 base.Load (filename);
125 public override void Load (TextReader txtReader)
127 base.Load (txtReader);
131 public override void Load (XmlReader xmlReader)
133 base.Load (xmlReader);
138 public override void Save (Stream stream)
144 public override void Save (string str)
147 base.Save (new XmlTextWriter (str, Encoding));