Author: atsushi
Date: 2008-02-15 15:17:11 -0500 (Fri, 15 Feb 2008)
New Revision: 95820

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-15  Atsushi Enomoto  <[EMAIL PROTECTED]>

        * WebMessageFormatter.cs : hack SerializeReply().
          Add WebBodyFormat property 

        * WebMessageEncoder.cs : consider WebBodyFormatMessageProperty.



Modified: 
trunk/olive/class/System.ServiceModel.Web/System.ServiceModel.Channels/ChangeLog
===================================================================
--- 
trunk/olive/class/System.ServiceModel.Web/System.ServiceModel.Channels/ChangeLog
    2008-02-15 20:16:58 UTC (rev 95819)
+++ 
trunk/olive/class/System.ServiceModel.Web/System.ServiceModel.Channels/ChangeLog
    2008-02-15 20:17:11 UTC (rev 95820)
@@ -1,3 +1,7 @@
+2008-02-15  Atsushi Enomoto  <[EMAIL PROTECTED]>
+
+       * WebMessageEncoder.cs : consider WebBodyFormatMessageProperty.
+
 2008-02-08  Atsushi Enomoto  <[EMAIL PROTECTED]>
 
        * WebMessageEncodingBindingElement.cs : removed some todos.

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-15 20:16:58 UTC (rev 95819)
+++ 
trunk/olive/class/System.ServiceModel.Web/System.ServiceModel.Channels/WebMessageEncoder.cs
 2008-02-15 20:17:11 UTC (rev 95820)
@@ -65,8 +65,12 @@
                        throw new NotImplementedException ();
                }
 
-               WebContentFormat GetContentFormat ()
+               WebContentFormat GetContentFormat (Message message)
                {
+                       string name = WebBodyFormatMessageProperty.Name;
+                       if (message.Properties.ContainsKey (name))
+                               return ((WebBodyFormatMessageProperty) 
message.Properties [name]).Format;
+
                        if (source.ContentTypeMapper != null)
                                return 
source.ContentTypeMapper.GetMessageFormatForContentType (ContentType);
                        switch (MediaType) {
@@ -92,7 +96,7 @@
                        if (stream == null)
                                throw new ArgumentNullException ("stream");
 
-                       switch (GetContentFormat ()) {
+                       switch (GetContentFormat (message)) {
                        case WebContentFormat.Xml:
                                using (XmlWriter w = 
XmlDictionaryWriter.CreateTextWriter (stream, source.WriteEncoding))
                                        message.WriteMessage (w);

Modified: 
trunk/olive/class/System.ServiceModel.Web/System.ServiceModel.Dispatcher/ChangeLog
===================================================================
--- 
trunk/olive/class/System.ServiceModel.Web/System.ServiceModel.Dispatcher/ChangeLog
  2008-02-15 20:16:58 UTC (rev 95819)
+++ 
trunk/olive/class/System.ServiceModel.Web/System.ServiceModel.Dispatcher/ChangeLog
  2008-02-15 20:17:11 UTC (rev 95820)
@@ -1,5 +1,10 @@
 2008-02-15  Atsushi Enomoto  <[EMAIL PROTECTED]>
 
+       * WebMessageFormatter.cs : hack SerializeReply().
+         Add WebBodyFormat property 
+
+2008-02-15  Atsushi Enomoto  <[EMAIL PROTECTED]>
+
        * WebMessageFormatter.cs : implement DeserializeRequest().
 
 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-15 20:16:58 UTC (rev 95819)
+++ 
trunk/olive/class/System.ServiceModel.Web/System.ServiceModel.Dispatcher/WebMessageFormatter.cs
     2008-02-15 20:17:11 UTC (rev 95820)
@@ -28,6 +28,8 @@
 using System;
 using System.Collections.Specialized;
 using System.Reflection;
+using System.Runtime.Serialization;
+using System.Runtime.Serialization.Json;
 using System.ServiceModel;
 using System.ServiceModel.Channels;
 using System.ServiceModel.Dispatcher;
@@ -72,6 +74,10 @@
                        message_desc = GetMessageDescription ();
                }
 
+               public WebHttpBehavior Behavior {
+                       get { return behavior; }
+               }
+
                public WebAttributeInfo Info {
                        get { return info; }
                }
@@ -98,6 +104,17 @@
 
                public abstract MessageDirection MessageDirection { get; }
 
+               protected WebContentFormat ToContentFormat (WebMessageFormat 
src)
+               {
+                       switch (src) {
+                       case WebMessageFormat.Xml:
+                               return WebContentFormat.Xml;
+                       case WebMessageFormat.Json:
+                               return WebContentFormat.Json;
+                       }
+                       throw new SystemException ("INTERNAL ERROR: should not 
happen");
+               }
+
                protected void CheckMessageVersion (MessageVersion 
messageVersion)
                {
                        if (messageVersion == null)
@@ -190,6 +207,9 @@
                                // FIXME: set hp.SuppressEntityBody for some 
cases.
                                ret.Properties.Add 
(HttpRequestMessageProperty.Name, hp);
 
+                               var wp = new WebBodyFormatMessageProperty 
(ToContentFormat (Info.IsRequestFormatSetExplicitly ? Info.RequestFormat : 
Behavior.DefaultOutgoingRequestFormat));
+                               ret.Properties.Add 
(WebBodyFormatMessageProperty.Name, wp);
+
                                return ret;
                        }
 
@@ -220,7 +240,45 @@
                                        throw new ArgumentNullException 
("parameters");
                                CheckMessageVersion (messageVersion);
 
-                               throw new NotImplementedException ();
+                               // FIXME: use them.
+                               // var dcob = 
Operation.Behaviors.Find<DataContractSerializerOperationBehavior> ();
+                               // XmlObjectSerializer xos = 
dcob.CreateSerializer (result.GetType (), MessageDescription.Body.WrapperName, 
MessageDescription.Body.WrapperNamespace, null);
+                               // var xsob = 
Operation.Behaviors.Find<XmlSerializerOperationBehavior> ();
+                               // XmlSerializer [] serializers = 
XmlSerializer.FromMappings (xsob.GetXmlMappings ().ToArray ());
+
+                               WebMessageFormat msgfmt = 
Info.IsResponseFormatSetExplicitly ? Info.ResponseFormat : 
Behavior.DefaultOutgoingResponseFormat;
+
+                               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;
+                                       }
+                               }
+
+                               // FIXME: serialize ref/out parameters as well.
+
+                               Message ret = Message.CreateMessage 
(MessageVersion.None, null, result, serializer);
+
+                               // Message properties
+
+                               var hp = new HttpResponseMessageProperty ();
+                               // FIXME: get encoding from somewhere
+                               hp.Headers ["Content-Type"] = mediaType + "; 
encoding=utf-8";
+                               // FIXME: fill some properties if required.
+                               ret.Properties.Add 
(HttpResponseMessageProperty.Name, hp);
+
+                               var wp = new WebBodyFormatMessageProperty 
(ToContentFormat (msgfmt));
+                               ret.Properties.Add 
(WebBodyFormatMessageProperty.Name, wp);
+
+                               return ret;
                        }
 
                        public void DeserializeRequest (Message message, object 
[] parameters)

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

Reply via email to