Fri Nov 24 18:38:31 CET 2006 Paolo Molaro <lupus@ximian.com>
[mono.git] / mcs / class / Microsoft.Web.Services / Microsoft.Web.Services.Messaging / SoapPlainFormatter.cs
1 //
2 // Microsoft.Web.Services.Messaging.SoapPlainFormatter.cs
3 //
4 // Author: Todd Berman <tberman@gentoo.org>
5 //
6 // (C) 2003 Todd Berman
7
8 using System;
9 using System.IO;
10
11 //FIXME: Can be removed when workaround is removed.
12 using System.Text;
13 using System.Net.Sockets;
14
15 using Microsoft.Web.Services;
16
17 namespace Microsoft.Web.Services.Messaging
18 {
19         public class SoapPlainFormatter : ISoapFormatter
20         {
21                 public SoapEnvelope Deserialize (Stream stream)
22                 {
23                         if(stream == null) {
24                                 throw new ArgumentNullException ("stream");
25                         }
26                         SoapEnvelope env = new SoapEnvelope ();
27                         //env.Load (stream);
28                         
29
30                         //FIXME: Workaround for XmlDocument.Load's love of stream closing
31                         byte[] buf = new byte[1024];
32                         String msg = "";
33                         int numRead = 0;
34                         
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);
39                         
40                         env.LoadXml (msg);
41                         
42                         return env;
43                 }
44
45                 [MonoTODO("Should error if envelope has DimeAttachments")]
46                 public void Serialize (SoapEnvelope env, Stream stream)
47                 {
48                         if(stream == null) {
49                                 throw new ArgumentNullException ("stream");
50                         }
51                         if(env == null) {
52                                 throw new ArgumentNullException ("envelope");
53                         }
54                         
55                         env.Save (stream);
56                         stream.Flush();
57                 }
58         }
59 }