diff options
author | Atsushi Eno <atsushieno@gmail.com> | 2009-10-07 22:30:51 +0400 |
---|---|---|
committer | Atsushi Eno <atsushieno@gmail.com> | 2009-10-07 22:30:51 +0400 |
commit | c213f959b43c9d27a69e261b4188954299117c5b (patch) | |
tree | dc72a7be4f3caedff15de2c6dfbc4470861ef498 /mcs/class/System.ServiceModel.Web/System.ServiceModel.Dispatcher | |
parent | baedd9881f3f0a7e53532ffad72f079b6851b99b (diff) |
2009-10-07 Atsushi Enomoto <atsushi@ximian.com>
* WebMessageFormatter.cs : revert and fix wrapper name change. XML
and JSON have different serialization.
svn path=/trunk/mcs/; revision=143697
Diffstat (limited to 'mcs/class/System.ServiceModel.Web/System.ServiceModel.Dispatcher')
-rw-r--r-- | mcs/class/System.ServiceModel.Web/System.ServiceModel.Dispatcher/ChangeLog | 5 | ||||
-rw-r--r-- | mcs/class/System.ServiceModel.Web/System.ServiceModel.Dispatcher/WebMessageFormatter.cs | 52 |
2 files changed, 44 insertions, 13 deletions
diff --git a/mcs/class/System.ServiceModel.Web/System.ServiceModel.Dispatcher/ChangeLog b/mcs/class/System.ServiceModel.Web/System.ServiceModel.Dispatcher/ChangeLog index 30b93baca4b..c68ab35f1a5 100644 --- a/mcs/class/System.ServiceModel.Web/System.ServiceModel.Dispatcher/ChangeLog +++ b/mcs/class/System.ServiceModel.Web/System.ServiceModel.Dispatcher/ChangeLog @@ -1,5 +1,10 @@ 2009-10-07 Atsushi Enomoto <atsushi@ximian.com> + * WebMessageFormatter.cs : revert and fix wrapper name change. XML + and JSON have different serialization. + +2009-10-07 Atsushi Enomoto <atsushi@ximian.com> + * WebMessageFormatter.cs : also fix wrapped message deserialization. It should expect FooResponse (body WrapperName), not FooResult (ReturnValue part Name). diff --git a/mcs/class/System.ServiceModel.Web/System.ServiceModel.Dispatcher/WebMessageFormatter.cs b/mcs/class/System.ServiceModel.Web/System.ServiceModel.Dispatcher/WebMessageFormatter.cs index 76c438ec669..60b24e49381 100644 --- a/mcs/class/System.ServiceModel.Web/System.ServiceModel.Dispatcher/WebMessageFormatter.cs +++ b/mcs/class/System.ServiceModel.Web/System.ServiceModel.Dispatcher/WebMessageFormatter.cs @@ -145,15 +145,15 @@ namespace System.ServiceModel.Description switch (msgfmt) { case WebContentFormat.Xml: if (IsResponseBodyWrapped) - return GetSerializer (ref xml_serializer, b => new DataContractSerializer (b.ReturnValue.Type, b.WrapperName, b.WrapperNamespace)); + return GetSerializer (ref xml_serializer, p => new DataContractSerializer (p.Type, p.Name, p.Namespace)); else - return GetSerializer (ref xml_serializer, b => new DataContractSerializer (b.ReturnValue.Type)); + return GetSerializer (ref xml_serializer, p => new DataContractSerializer (p.Type)); break; case WebContentFormat.Json: if (IsResponseBodyWrapped) - return GetSerializer (ref json_serializer, b => new DataContractJsonSerializer (b.ReturnValue.Type, b.WrapperName)); + return GetSerializer (ref json_serializer, p => new DataContractJsonSerializer (p.Type, p.Name)); else - return GetSerializer (ref json_serializer, b => new DataContractJsonSerializer (b.ReturnValue.Type)); + return GetSerializer (ref json_serializer, p => new DataContractJsonSerializer (p.Type)); break; default: throw new NotImplementedException (); @@ -162,11 +162,11 @@ namespace System.ServiceModel.Description XmlObjectSerializer xml_serializer, json_serializer; - XmlObjectSerializer GetSerializer (ref XmlObjectSerializer serializer, Func<MessageBodyDescription,XmlObjectSerializer> f) + XmlObjectSerializer GetSerializer (ref XmlObjectSerializer serializer, Func<MessagePartDescription,XmlObjectSerializer> f) { if (serializer == null) { MessageDescription md = GetMessageDescription (MessageDirection.Output); - serializer = f (md.Body); + serializer = f (md.Body.ReturnValue); } return serializer; } @@ -293,8 +293,12 @@ namespace System.ServiceModel.Description var reader = message.GetReaderAtBodyContents (); - if (IsResponseBodyWrapped) - reader.ReadStartElement ("root", String.Empty); // note that the wrapper name is passed to the serializer. + if (IsResponseBodyWrapped) { + if (wp.Format == WebContentFormat.Json) + reader.ReadStartElement ("root", String.Empty); // note that the wrapper name is passed to the serializer. + else + reader.ReadStartElement (md.Body.WrapperName, md.Body.WrapperNamespace); + } var ret = serializer.ReadObject (reader, true); @@ -307,26 +311,36 @@ namespace System.ServiceModel.Description internal class WrappedBodyWriter : BodyWriter { - public WrappedBodyWriter (object value, XmlObjectSerializer serializer, string name, string ns) + public WrappedBodyWriter (object value, XmlObjectSerializer serializer, string name, string ns, bool json) : base (true) { this.name = name; this.ns = ns; this.value = value; this.serializer = serializer; + this.is_json = json; } + bool is_json; string name, ns; object value; XmlObjectSerializer serializer; protected override BodyWriter OnCreateBufferedCopy (int maxBufferSize) { - return new WrappedBodyWriter (value, serializer, name, ns); + return new WrappedBodyWriter (value, serializer, name, ns, is_json); } protected override void OnWriteBodyContents (XmlDictionaryWriter writer) { + if (is_json) + WriteJsonBodyContents (writer); + else + WriteXmlBodyContents (writer); + } + + void WriteJsonBodyContents (XmlDictionaryWriter writer) + { writer.WriteStartElement ("root"); if (name != null) { writer.WriteAttributeString ("type", "object"); @@ -337,6 +351,15 @@ namespace System.ServiceModel.Description writer.WriteEndElement (); writer.WriteEndElement (); } + + void WriteXmlBodyContents (XmlDictionaryWriter writer) + { + if (name != null) + writer.WriteStartElement (name, ns); + serializer.WriteObject (writer, value); + if (name != null) + writer.WriteEndElement (); + } } internal abstract class WebDispatchMessageFormatter : WebMessageFormatter, IDispatchMessageFormatter @@ -377,22 +400,25 @@ namespace System.ServiceModel.Description // FIXME: serialize ref/out parameters as well. - string name = IsResponseBodyWrapped ? md.Body.WrapperName : null; - string ns = IsResponseBodyWrapped ? md.Body.WrapperNamespace : null; + string name = null, ns = null; switch (msgfmt) { case WebMessageFormat.Xml: serializer = GetSerializer (WebContentFormat.Xml); mediaType = "application/xml"; + name = IsResponseBodyWrapped ? md.Body.WrapperName : null; + ns = IsResponseBodyWrapped ? md.Body.WrapperNamespace : null; break; case WebMessageFormat.Json: serializer = GetSerializer (WebContentFormat.Json); mediaType = "application/json"; + name = IsResponseBodyWrapped ? md.Body.ReturnValue.Name : null; ns = String.Empty; break; } - Message ret = Message.CreateMessage (MessageVersion.None, null, new WrappedBodyWriter (result, serializer, name, ns)); + bool json = msgfmt == WebMessageFormat.Json; + Message ret = Message.CreateMessage (MessageVersion.None, null, new WrappedBodyWriter (result, serializer, name, ns, json)); // Message properties |