diff options
author | Atsushi Eno <atsushieno@gmail.com> | 2009-10-08 12:59:56 +0400 |
---|---|---|
committer | Atsushi Eno <atsushieno@gmail.com> | 2009-10-08 12:59:56 +0400 |
commit | cd263cb1f496adb927884bbc5b5a56a4e9124d8a (patch) | |
tree | 969656e094feb1a86fe7e2ea4804feb10c3c9250 /mcs/class/System.ServiceModel.Web/System.ServiceModel.Dispatcher | |
parent | 9a5b774b75b3da7c55329d6a2e9a5c873b443144 (diff) |
2009-10-08 Atsushi Enomoto <atsushi@ximian.com>
* JsonQueryStringConverter.cs : add custom body name support (used.
for AJAX). Handle string value (in very LAMESPEC way).
* WebMessageFormatter.cs : add custom body name support.
Slightly changed reply serialization.
Convert deserialized values using QueryStringConverter.
* WebScriptEnablingBehavior.cs : use JsonQueryStringConverter, with
"d" wrapper name. Allow only WrappedRequest.
* JsonQueryStringConverterTest.cs : added some string deserialization
test. It just proved .NET is too lame.
svn path=/trunk/mcs/; revision=143747
Diffstat (limited to 'mcs/class/System.ServiceModel.Web/System.ServiceModel.Dispatcher')
3 files changed, 32 insertions, 10 deletions
diff --git a/mcs/class/System.ServiceModel.Web/System.ServiceModel.Dispatcher/ChangeLog b/mcs/class/System.ServiceModel.Web/System.ServiceModel.Dispatcher/ChangeLog index c68ab35f1a5..068f52ffde6 100644 --- a/mcs/class/System.ServiceModel.Web/System.ServiceModel.Dispatcher/ChangeLog +++ b/mcs/class/System.ServiceModel.Web/System.ServiceModel.Dispatcher/ChangeLog @@ -1,3 +1,11 @@ +2009-10-08 Atsushi Enomoto <atsushi@ximian.com> + + * JsonQueryStringConverter.cs : add custom body name support (used. + for AJAX). Handle string value (in very LAMESPEC way). + * WebMessageFormatter.cs : add custom body name support. + Slightly changed reply serialization. + Convert deserialized values using QueryStringConverter. + 2009-10-07 Atsushi Enomoto <atsushi@ximian.com> * WebMessageFormatter.cs : revert and fix wrapper name change. XML diff --git a/mcs/class/System.ServiceModel.Web/System.ServiceModel.Dispatcher/JsonQueryStringConverter.cs b/mcs/class/System.ServiceModel.Web/System.ServiceModel.Dispatcher/JsonQueryStringConverter.cs index 121bc13541c..21fe49b6934 100644 --- a/mcs/class/System.ServiceModel.Web/System.ServiceModel.Dispatcher/JsonQueryStringConverter.cs +++ b/mcs/class/System.ServiceModel.Web/System.ServiceModel.Dispatcher/JsonQueryStringConverter.cs @@ -40,6 +40,8 @@ namespace System.ServiceModel.Dispatcher { DataContractJsonSerializer serializer = new DataContractJsonSerializer (typeof (object)); + internal string CustomWrapperName { get; set; } + public override bool CanConvert (Type type) { // almost copy from QueryStringConverter, except that DBNull and XmlQualifiedName are supported @@ -79,8 +81,15 @@ namespace System.ServiceModel.Dispatcher // the target type in JSON context. switch (Type.GetTypeCode (parameterType)) { - //case TypeCode.String: - // return parameter; + case TypeCode.String: + // LAMESPEC LAMESPEC LAMESPEC: we cannot give "foo" as the string value input (even if they are escaped as %22!) + if (parameter == null) + return null; + if (parameter.Length > 1 && parameter [0] == '"' && parameter [parameter.Length - 1] == '"') + return parameter.Substring (1, parameter.Length - 2); + else if (parameter [0] != '"') + return parameter; + break; case TypeCode.Char: return parameter != null ? Char.Parse (parameter): default (char); case TypeCode.SByte: 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 60b24e49381..90a49d4de18 100644 --- a/mcs/class/System.ServiceModel.Web/System.ServiceModel.Dispatcher/WebMessageFormatter.cs +++ b/mcs/class/System.ServiceModel.Web/System.ServiceModel.Dispatcher/WebMessageFormatter.cs @@ -55,6 +55,10 @@ namespace System.ServiceModel.Description this.converter = converter; this.behavior = behavior; ApplyWebAttribute (); + // This is a hack for WebScriptEnablingBehavior + var jqc = converter as JsonQueryStringConverter; + if (jqc != null) + BodyName = jqc.CustomWrapperName; } void ApplyWebAttribute () @@ -73,6 +77,8 @@ namespace System.ServiceModel.Description template = info.BuildUriTemplate (Operation, GetMessageDescription (MessageDirection.Input)); } + public string BodyName { get; set; } + public WebHttpBehavior Behavior { get { return behavior; } } @@ -92,7 +98,7 @@ namespace System.ServiceModel.Description case WebMessageBodyStyle.WrappedResponse: return true; } - return false; + return BodyName != null; } } @@ -151,7 +157,7 @@ namespace System.ServiceModel.Description break; case WebContentFormat.Json: if (IsResponseBodyWrapped) - return GetSerializer (ref json_serializer, p => new DataContractJsonSerializer (p.Type, p.Name)); + return GetSerializer (ref json_serializer, p => new DataContractJsonSerializer (p.Type, BodyName ?? p.Name)); else return GetSerializer (ref json_serializer, p => new DataContractJsonSerializer (p.Type)); break; @@ -341,15 +347,13 @@ namespace System.ServiceModel.Description void WriteJsonBodyContents (XmlDictionaryWriter writer) { - writer.WriteStartElement ("root"); if (name != null) { + writer.WriteStartElement ("root"); writer.WriteAttributeString ("type", "object"); - writer.WriteStartElement (name, ns); } - serializer.WriteObjectContent (writer, value); + serializer.WriteObject (writer, value); if (name != null) writer.WriteEndElement (); - writer.WriteEndElement (); } void WriteXmlBodyContents (XmlDictionaryWriter writer) @@ -412,7 +416,7 @@ namespace System.ServiceModel.Description case WebMessageFormat.Json: serializer = GetSerializer (WebContentFormat.Json); mediaType = "application/json"; - name = IsResponseBodyWrapped ? md.Body.ReturnValue.Name : null; + name = IsResponseBodyWrapped ? (BodyName ?? md.Body.ReturnValue.Name) : null; ns = String.Empty; break; } @@ -460,7 +464,8 @@ namespace System.ServiceModel.Description for (int i = 0; i < parameters.Length; i++) { var p = md.Body.Parts [i]; string name = p.Name.ToUpperInvariant (); - parameters [i] = match.BoundVariables [name]; + var str = match.BoundVariables [name]; + parameters [i] = Converter.ConvertStringToValue (str, p.Type); } } } |