Author: atsushi
Date: 2008-02-16 04:05:28 -0500 (Sat, 16 Feb 2008)
New Revision: 95855

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

        * WebMessageFormatter.cs : implemented DeserializeReply().
          It was wrong to have one MessageDescription in a formatter, as
          they are different between serialization and deserialization.

        * WebMessageEncoder.cs : attach WebBodyFormatMessageProperty in
          ReadMessage() too.



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:58:49 UTC (rev 95854)
+++ 
trunk/olive/class/System.ServiceModel.Web/System.ServiceModel.Channels/ChangeLog
    2008-02-16 09:05:28 UTC (rev 95855)
@@ -1,5 +1,10 @@
 2008-02-16  Atsushi Enomoto  <[EMAIL PROTECTED]>
 
+       * WebMessageEncoder.cs : attach WebBodyFormatMessageProperty in
+         ReadMessage() too.
+
+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/WebMessageEncoder.cs
===================================================================
--- 
trunk/olive/class/System.ServiceModel.Web/System.ServiceModel.Channels/WebMessageEncoder.cs
 2008-02-16 07:58:49 UTC (rev 95854)
+++ 
trunk/olive/class/System.ServiceModel.Web/System.ServiceModel.Channels/WebMessageEncoder.cs
 2008-02-16 09:05:28 UTC (rev 95855)
@@ -79,18 +79,27 @@
                        if (ct.CharSet != null)
                                enc = Encoding.GetEncoding (ct.CharSet);
 
+                       Message msg = null;
+                       WebBodyFormatMessageProperty wp = null;
                        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)));
+                               msg = Message.CreateMessage 
(MessageVersion.None, null, XmlReader.Create (new StreamReader (stream, enc)));
+                               wp = new WebBodyFormatMessageProperty 
(WebContentFormat.Xml);
+                               break;
                        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));
+                               msg = Message.CreateMessage 
(MessageVersion.None, null, JsonReaderWriterFactory.CreateJsonReader (stream, 
enc, source.ReaderQuotas, null));
+                               wp = new WebBodyFormatMessageProperty 
(WebContentFormat.Json);
+                               break;
                        case WebContentFormat.Raw:
                                throw new NotImplementedException ();
                        default:
                                throw new SystemException ("INTERNAL ERROR: 
cannot determine content format");
                        }
+                       if (wp != null)
+                               msg.Properties.Add 
(WebBodyFormatMessageProperty.Name, wp);
+                       return msg;
                }
 
                WebContentFormat GetContentFormat (Message message)

Modified: 
trunk/olive/class/System.ServiceModel.Web/System.ServiceModel.Dispatcher/ChangeLog
===================================================================
--- 
trunk/olive/class/System.ServiceModel.Web/System.ServiceModel.Dispatcher/ChangeLog
  2008-02-16 07:58:49 UTC (rev 95854)
+++ 
trunk/olive/class/System.ServiceModel.Web/System.ServiceModel.Dispatcher/ChangeLog
  2008-02-16 09:05:28 UTC (rev 95855)
@@ -1,5 +1,11 @@
 2008-02-16  Atsushi Enomoto  <[EMAIL PROTECTED]>
 
+       * WebMessageFormatter.cs : implemented DeserializeReply().
+         It was wrong to have one MessageDescription in a formatter, as
+         they are different between serialization and deserialization.
+
+2008-02-16  Atsushi Enomoto  <[EMAIL PROTECTED]>
+
        * WebMessageFormatter.cs : oops oops. not "encoding" but "charset".
 
 2008-02-15  Atsushi Enomoto  <[EMAIL PROTECTED]>

Modified: 
trunk/olive/class/System.ServiceModel.Web/System.ServiceModel.Dispatcher/WebMessageFormatter.cs
===================================================================
--- 
trunk/olive/class/System.ServiceModel.Web/System.ServiceModel.Dispatcher/WebMessageFormatter.cs
     2008-02-16 07:58:49 UTC (rev 95854)
+++ 
trunk/olive/class/System.ServiceModel.Web/System.ServiceModel.Dispatcher/WebMessageFormatter.cs
     2008-02-16 09:05:28 UTC (rev 95855)
@@ -41,7 +41,6 @@
        internal abstract class WebMessageFormatter
        {
                OperationDescription operation;
-               MessageDescription message_desc;
                ServiceEndpoint endpoint;
                QueryStringConverter converter;
                WebHttpBehavior behavior;
@@ -70,8 +69,7 @@
                        if (info == null)
                                info = new WebAttributeInfo ();
 
-                       template = info.BuildUriTemplate (Operation, 
GetMessageDescription ());
-                       message_desc = GetMessageDescription ();
+                       template = info.BuildUriTemplate (Operation, 
GetMessageDescription (MessageDirection.Input));
                }
 
                public WebHttpBehavior Behavior {
@@ -86,10 +84,6 @@
                        get { return operation; }
                }
 
-               public MessageDescription MessageDescription {
-                       get { return message_desc; }
-               }
-
                public QueryStringConverter Converter {
                        get { return converter; }
                }
@@ -102,8 +96,6 @@
                        get { return template; }
                }
 
-               public abstract MessageDirection MessageDirection { get; }
-
                protected WebContentFormat ToContentFormat (WebMessageFormat 
src)
                {
                        switch (src) {
@@ -124,12 +116,12 @@
                                throw new ArgumentException ("Only 
MessageVersion.None is supported");
                }
 
-               MessageDescription GetMessageDescription ()
+               protected MessageDescription GetMessageDescription 
(MessageDirection dir)
                {
                        foreach (MessageDescription md in operation.Messages)
-                               if (md.Direction == this.MessageDirection)
+                               if (md.Direction == dir)
                                        return md;
-                       throw new SystemException ("INTERNAL ERROR: no 
corresponding message description for the specified direction: " + 
MessageDirection);
+                       throw new SystemException ("INTERNAL ERROR: no 
corresponding message description for the specified direction: " + dir);
                }
 
                internal class RequestClientFormatter : 
WebClientMessageFormatter
@@ -171,10 +163,6 @@
                        {
                        }
 
-                       public override MessageDirection MessageDirection {
-                               get { return MessageDirection.Input; }
-                       }
-
                        public Message SerializeRequest (MessageVersion 
messageVersion, object [] parameters)
                        {
                                if (parameters == null)
@@ -183,11 +171,13 @@
 
                                var c = new NameValueCollection ();
 
-                               if (parameters.Length != 
MessageDescription.Body.Parts.Count)
+                               MessageDescription md = GetMessageDescription 
(MessageDirection.Input);
+
+                               if (parameters.Length != md.Body.Parts.Count)
                                        throw new ArgumentException ("Parameter 
array length does not match the number of message body parts");
 
                                for (int i = 0; i < parameters.Length; i++) {
-                                       var p = MessageDescription.Body.Parts 
[i];
+                                       var p = md.Body.Parts [i];
                                        string name = p.Name.ToUpperInvariant 
();
                                        if 
(UriTemplate.PathSegmentVariableNames.Contains (name) ||
                                            
UriTemplate.QueryValueVariableNames.Contains (name))
@@ -219,7 +209,28 @@
                                        throw new ArgumentNullException 
("parameters");
                                CheckMessageVersion (message.Version);
 
-                               throw new NotImplementedException ();
+                               string pname = 
WebBodyFormatMessageProperty.Name;
+                               if (!message.Properties.ContainsKey (pname))
+                                       throw new SystemException ("INTERNAL 
ERROR: it expects WebBodyFormatMessageProperty existence");
+                               var wp = (WebBodyFormatMessageProperty) 
message.Properties [pname];
+                               MessageDescription md = GetMessageDescription 
(MessageDirection.Output);
+
+                               XmlObjectSerializer serializer = null;
+                               switch (wp.Format) {
+                               case WebContentFormat.Xml:
+                                       serializer = new DataContractSerializer 
(md.Body.ReturnValue.Type);
+                                       break;
+                               case WebContentFormat.Json:
+                                       serializer = new 
DataContractJsonSerializer (md.Body.ReturnValue.Type);
+                                       break;
+                               case WebContentFormat.Raw:
+                               default:
+                                       throw new NotImplementedException ();
+                               }
+
+                               // FIXME: handle ref/out parameters
+
+                               return serializer.ReadObject 
(message.GetReaderAtBodyContents ());
                        }
                }
 
@@ -230,19 +241,17 @@
                        {
                        }
 
-                       public override MessageDirection MessageDirection {
-                               get { return MessageDirection.Input; }
-                       }
-
                        public Message SerializeReply (MessageVersion 
messageVersion, object [] parameters, object result)
                        {
                                if (parameters == null)
                                        throw new ArgumentNullException 
("parameters");
                                CheckMessageVersion (messageVersion);
 
+                               MessageDescription md = GetMessageDescription 
(MessageDirection.Output);
+
                                // FIXME: use them.
                                // var dcob = 
Operation.Behaviors.Find<DataContractSerializerOperationBehavior> ();
-                               // XmlObjectSerializer xos = 
dcob.CreateSerializer (result.GetType (), MessageDescription.Body.WrapperName, 
MessageDescription.Body.WrapperNamespace, null);
+                               // XmlObjectSerializer xos = 
dcob.CreateSerializer (result.GetType (), md.Body.WrapperName, 
md.Body.WrapperNamespace, null);
                                // var xsob = 
Operation.Behaviors.Find<XmlSerializerOperationBehavior> ();
                                // XmlSerializer [] serializers = 
XmlSerializer.FromMappings (xsob.GetXmlMappings ().ToArray ());
 
@@ -250,17 +259,15 @@
 
                                string mediaType = null;
                                XmlObjectSerializer serializer = null;
-                               if (result != null) {
-                                       switch (msgfmt) {
-                                       case WebMessageFormat.Xml:
-                                               serializer = new 
DataContractSerializer (result.GetType ());
-                                               mediaType = "application/xml";
-                                               break;
-                                       case WebMessageFormat.Json:
-                                               serializer = new 
DataContractJsonSerializer (result.GetType ());
-                                               mediaType = "appllication/json";
-                                               break;
-                                       }
+                               switch (msgfmt) {
+                               case WebMessageFormat.Xml:
+                                       serializer = new DataContractSerializer 
(md.Body.ReturnValue.Type);
+                                       mediaType = "application/xml";
+                                       break;
+                               case WebMessageFormat.Json:
+                                       serializer = new 
DataContractJsonSerializer (md.Body.ReturnValue.Type);
+                                       mediaType = "appllication/json";
+                                       break;
                                }
 
                                // FIXME: serialize ref/out parameters as well.
@@ -292,8 +299,11 @@
                                if (match == null)
                                        // not sure if it could happen
                                        throw new SystemException 
(String.Format ("INTERNAL ERROR: UriTemplate does not match with the request: 
{0} / {1}", UriTemplate, to));
+
+                               MessageDescription md = GetMessageDescription 
(MessageDirection.Input);
+
                                for (int i = 0; i < parameters.Length; i++) {
-                                       var p = MessageDescription.Body.Parts 
[i];
+                                       var p = md.Body.Parts [i];
                                        string name = p.Name.ToUpperInvariant 
();
                                        parameters [i] = match.BoundVariables 
[name];
                                }

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

Reply via email to