Author: atsushi
Date: 2008-02-16 02:57:41 -0500 (Sat, 16 Feb 2008)
New Revision: 95853

Modified:
   
trunk/olive/class/System.ServiceModel.Web/System.ServiceModel.Channels/ChangeLog
   
trunk/olive/class/System.ServiceModel.Web/System.ServiceModel.Channels/WebMessageEncoder.cs
Log:
2008-02-16  Atsushi Enomoto  <[EMAIL PROTECTED]>

        * WebMessageEncoder.cs : implement ReadMessage(Stream,...). Use
          ContentTypeMapper here, not in WriteMessage().



Modified: 
trunk/olive/class/System.ServiceModel.Web/System.ServiceModel.Channels/ChangeLog
===================================================================
--- 
trunk/olive/class/System.ServiceModel.Web/System.ServiceModel.Channels/ChangeLog
    2008-02-16 07:56:43 UTC (rev 95852)
+++ 
trunk/olive/class/System.ServiceModel.Web/System.ServiceModel.Channels/ChangeLog
    2008-02-16 07:57:41 UTC (rev 95853)
@@ -1,3 +1,8 @@
+2008-02-16  Atsushi Enomoto  <[EMAIL PROTECTED]>
+
+       * WebMessageEncoder.cs : implement ReadMessage(Stream,...). Use
+         ContentTypeMapper here, not in WriteMessage().
+
 2008-02-15  Atsushi Enomoto  <[EMAIL PROTECTED]>
 
        * WebMessageEncoder.cs : consider WebBodyFormatMessageProperty.

Modified: 
trunk/olive/class/System.ServiceModel.Web/System.ServiceModel.Channels/WebMessageEncoder.cs
===================================================================
--- 
trunk/olive/class/System.ServiceModel.Web/System.ServiceModel.Channels/WebMessageEncoder.cs
 2008-02-16 07:56:43 UTC (rev 95852)
+++ 
trunk/olive/class/System.ServiceModel.Web/System.ServiceModel.Channels/WebMessageEncoder.cs
 2008-02-16 07:57:41 UTC (rev 95853)
@@ -27,8 +27,10 @@
 //
 using System;
 using System.IO;
+using System.Net.Mime;
 using System.Runtime.Serialization.Json;
 using System.ServiceModel;
+using System.Text;
 using System.Xml;
 
 namespace System.ServiceModel.Channels
@@ -62,7 +64,33 @@
 
                public override Message ReadMessage (Stream stream, int 
maxSizeOfHeaders, string contentType)
                {
-                       throw new NotImplementedException ();
+                       if (stream == null)
+                               throw new ArgumentNullException ("stream");
+                       if (contentType == null)
+                               throw new ArgumentNullException ("contentType");
+
+                       WebContentFormat fmt = WebContentFormat.Xml;
+                       if (source.ContentTypeMapper != null)
+                               fmt = 
source.ContentTypeMapper.GetMessageFormatForContentType (ContentType);
+
+                       Encoding enc = Encoding.UTF8;
+Console.WriteLine (contentType);
+                       ContentType ct = new ContentType (contentType);
+                       if (ct.CharSet != null)
+                               enc = Encoding.GetEncoding (ct.CharSet);
+
+                       switch (fmt) {
+                       case WebContentFormat.Xml:
+                               // FIXME: is it safe/unsafe/required to keep 
XmlReader open?
+                               return Message.CreateMessage 
(MessageVersion.None, null, XmlReader.Create (new StreamReader (stream, enc)));
+                       case WebContentFormat.Json:
+                               // FIXME: is it safe/unsafe/required to keep 
XmlReader open?
+                               return Message.CreateMessage 
(MessageVersion.None, null, JsonReaderWriterFactory.CreateJsonReader (stream, 
enc, source.ReaderQuotas, null));
+                       case WebContentFormat.Raw:
+                               throw new NotImplementedException ();
+                       default:
+                               throw new SystemException ("INTERNAL ERROR: 
cannot determine content format");
+                       }
                }
 
                WebContentFormat GetContentFormat (Message message)
@@ -71,8 +99,6 @@
                        if (message.Properties.ContainsKey (name))
                                return ((WebBodyFormatMessageProperty) 
message.Properties [name]).Format;
 
-                       if (source.ContentTypeMapper != null)
-                               return 
source.ContentTypeMapper.GetMessageFormatForContentType (ContentType);
                        switch (MediaType) {
                        case "application/xml":
                        case "text/xml":

_______________________________________________
Mono-patches maillist  -  [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches

Reply via email to