**** Merged from MCS ****
[mono-project.git] / mcs / class / Microsoft.Web.Services / Microsoft.Web.Services.Messaging / SoapPlainFormatter.cs
blobb56b022a085da95a6fb873060b00d7d9475c931b
1 //
2 // Microsoft.Web.Services.Messaging.SoapPlainFormatter.cs
3 //
4 // Author: Todd Berman <tberman@gentoo.org>
5 //
6 // (C) 2003 Todd Berman
8 using System;
9 using System.IO;
11 //FIXME: Can be removed when workaround is removed.
12 using System.Text;
13 using System.Net.Sockets;
15 using Microsoft.Web.Services;
17 namespace Microsoft.Web.Services.Messaging
19 public class SoapPlainFormatter : ISoapFormatter
21 public SoapEnvelope Deserialize (Stream stream)
23 if(stream == null) {
24 throw new ArgumentNullException ("stream");
26 SoapEnvelope env = new SoapEnvelope ();
27 //env.Load (stream);
30 //FIXME: Workaround for XmlDocument.Load's love of stream closing
31 byte[] buf = new byte[1024];
32 String msg = "";
33 int numRead = 0;
35 do {
36 numRead = stream.Read(buf, 0, buf.Length);
37 msg = String.Concat (msg, Encoding.ASCII.GetString (buf, 0, numRead));
38 } while(((NetworkStream)stream).DataAvailable);
40 env.LoadXml (msg);
42 return env;
45 [MonoTODO("Should error if envelope has DimeAttachments")]
46 public void Serialize (SoapEnvelope env, Stream stream)
48 if(stream == null) {
49 throw new ArgumentNullException ("stream");
51 if(env == null) {
52 throw new ArgumentNullException ("envelope");
55 env.Save (stream);
56 stream.Flush();