* SoapReader.cs: If the SoapMessage instance being filled includes the
authorLluis Sanchez <lluis@novell.com>
Fri, 30 Apr 2004 09:04:06 +0000 (09:04 -0000)
committerLluis Sanchez <lluis@novell.com>
Fri, 30 Apr 2004 09:04:06 +0000 (09:04 -0000)
  array of parameter types, use those to deserialize the parameter values.
  Use the new method SoapTypeMapper.ParseXsdValue() to parse primitive values.
* SoapTypeMapper.cs: Added GetXsdValue and ParseXsdValue.
* SoapWriter.cs: Always include parameter types when serializing a message.
  MS.NET does it.

svn path=/trunk/mcs/; revision=26400

mcs/class/System.Runtime.Serialization.Formatters.Soap/System.Runtime.Serialization.Formatters.Soap/ChangeLog
mcs/class/System.Runtime.Serialization.Formatters.Soap/System.Runtime.Serialization.Formatters.Soap/SoapReader.cs
mcs/class/System.Runtime.Serialization.Formatters.Soap/System.Runtime.Serialization.Formatters.Soap/SoapTypeMapper.cs
mcs/class/System.Runtime.Serialization.Formatters.Soap/System.Runtime.Serialization.Formatters.Soap/SoapWriter.cs

index b72ff27959d7c4c888234e67bacbe435810038e9..b4506bed314204e58eefd78f36daadbf48c591c4 100644 (file)
@@ -1,3 +1,12 @@
+2004-04-30  Lluis Sanchez Gual <lluis@ximian.com>
+
+       * SoapReader.cs: If the SoapMessage  instance being filled includes the
+         array of parameter types, use those to deserialize the parameter values.
+         Use the new method SoapTypeMapper.ParseXsdValue() to parse primitive values.
+       * SoapTypeMapper.cs: Added GetXsdValue and ParseXsdValue.
+       * SoapWriter.cs: Always include parameter types when serializing a message.
+         MS.NET does it.
+
 2003-03-18 David Sheldon <dave-mono@earth.li>
 
   * SoapTypeMapper.cs: Map object to xsd:anyType rather than 
index 6584da8ae300e7ee2eca625f6516bd0cd638c002..843c3b168cd5c4862480f2014a9c12ee87419b50 100755 (executable)
@@ -9,6 +9,7 @@
 using System;\r
 using System.IO;\r
 using System.Xml;\r
+using System.Xml.Schema;\r
 using System.Reflection;\r
 using System.Collections;\r
 using System.Runtime.Remoting;\r
@@ -115,7 +116,7 @@ namespace System.Runtime.Serialization.Formatters.Soap {
 \r
                private bool IsNull()\r
                {\r
-                       string tmp = xmlReader["xsi:null"];\r
+                       string tmp = xmlReader["null", XmlSchema.InstanceNamespace];\r
                        return (tmp == null || tmp == string.Empty)?false:true;\r
                }\r
 \r
@@ -143,7 +144,8 @@ namespace System.Runtime.Serialization.Formatters.Soap {
                {\r
                        Type type = null;\r
                        if(GetId() != 0) return typeof(string);\r
-                       string strValue = xmlReader["xsi:type"];\r
+                       \r
+                       string strValue = xmlReader["type", XmlSchema.InstanceNamespace];\r
                        if(strValue == null) return null;\r
                        string[] strName = strValue.Split(':');\r
                        string namespaceURI = xmlReader.LookupNamespace(strName[0]);\r
@@ -181,10 +183,18 @@ namespace System.Runtime.Serialization.Formatters.Soap {
                        {\r
                                long paramId, paramHref;\r
                                object objParam = null;\r
-                               paramNames.Add(xmlReader.Name);\r
+                               paramNames.Add (xmlReader.Name);\r
+                               Type paramType = null;\r
+                               \r
+                               if (message.ParamTypes != null) {\r
+                                       if (i >= message.ParamTypes.Length)\r
+                                               throw new SerializationException ("Not enough parameter types in SoapMessages");\r
+                                       paramType = message.ParamTypes [i];\r
+                               }\r
+                               \r
                                indices[0] = i;\r
                                objParam = DeserializeComponent(\r
-                                       null,\r
+                                       paramType,\r
                                        out paramId,\r
                                        out paramHref,\r
                                        paramValuesId,\r
@@ -197,7 +207,7 @@ namespace System.Runtime.Serialization.Formatters.Soap {
                                }\r
                                else if(paramId != 0) \r
                                {\r
-                                       RegisterObject(paramId, objParam, null, paramValuesId, null, indices);\r
+//                                     RegisterObject(paramId, objParam, null, paramValuesId, null, indices);\r
                                }\r
                                else \r
                                {\r
@@ -347,11 +357,8 @@ namespace System.Runtime.Serialization.Formatters.Soap {
                        if(SoapTypeMapper.CanBeValue(type)) \r
                        {\r
                                string elementString = xmlReader.ReadElementString();\r
-                               object obj;\r
-                               if(type.IsEnum)\r
-                                       obj = Enum.Parse(type, elementString);\r
-                               else\r
-                                       obj = Convert.ChangeType(elementString, type);\r
+                               object obj = SoapTypeMapper.ParseXsdValue (elementString, type);\r
+                               \r
                                if(id > 0) \r
                                        RegisterObject(id, obj, info, parentId, parentMemberInfo, indices);\r
 \r
@@ -594,7 +601,6 @@ namespace System.Runtime.Serialization.Formatters.Soap {
                {\r
                        if (parentObjectId == 0) indices = null;\r
 \r
-\r
                        if (!objectInstance.GetType().IsValueType || parentObjectId == 0)\r
                                objMgr.RegisterObject (objectInstance, objectId, info, 0, null, null);\r
                        else\r
index fe1d7bf684b140ea059453aef48d88f8a8c36fef..f62e2150622fc18e37fc5e103d5df6c2d7b7e869 100644 (file)
@@ -14,6 +14,8 @@ using System.Xml;
 using System.Xml.Serialization;
 using System.Runtime.Serialization.Formatters;
 using System.Xml.Schema;
+using System.Runtime.Remoting.Metadata.W3cXsd2001;
+using System.Globalization;
 
 namespace System.Runtime.Serialization.Formatters.Soap {
 
@@ -338,7 +340,53 @@ namespace System.Runtime.Serialization.Formatters.Soap {
 
 
                }
-
+               
+               public static string GetXsdValue (object value)
+               {
+                       if (value is DateTime) {
+                               return SoapDateTime.ToString ((DateTime)value);
+                       }
+                       else if (value is decimal) {
+                               return ((decimal) value).ToString (CultureInfo.InvariantCulture);
+                       }
+                       else if (value is double) {
+                               return ((double) value).ToString (CultureInfo.InvariantCulture);
+                       }
+                       else if (value is float) {
+                               return ((float) value).ToString (CultureInfo.InvariantCulture);
+                       }
+                       else if (value is TimeSpan) {
+                               return SoapDuration.ToString ((TimeSpan)value);
+                       }
+                       else {
+                               return value.ToString ();
+                       }
+               }
+               
+               public static object ParseXsdValue (string value, Type type)
+               {
+                       if (type == typeof(DateTime)) {
+                               return SoapDateTime.Parse (value);
+                       }
+                       else if (type == typeof(decimal)) {
+                               return decimal.Parse (value, CultureInfo.InvariantCulture);
+                       }
+                       else if (type == typeof(double)) {
+                               return double.Parse (value, CultureInfo.InvariantCulture);
+                       }
+                       else if (type == typeof(float)) {
+                               return float.Parse (value, CultureInfo.InvariantCulture);
+                       }
+                       else if (type == typeof (TimeSpan)) {
+                               return SoapDuration.Parse (value);
+                       }
+                       else if(type.IsEnum) {
+                               return Enum.Parse(type, value);
+                       }
+                       else {
+                               return Convert.ChangeType (value, type, CultureInfo.InvariantCulture);
+                       }
+               }
 
        }
 }
index 0664da48be01ccd0ce6c1f03b2330e3bdb2942df..f270eb3e7ae6efadc5b4dbd4b84213b00eb6eb26 100755 (executable)
@@ -268,13 +268,10 @@ namespace System.Runtime.Serialization.Formatters.Soap {
                        Type[] paramTypes = message.ParamTypes;\r
                        object[] paramValues = message.ParamValues;\r
                        int length = (paramNames != null)?paramNames.Length:0;\r
-\r
                        for(int i = 0; i < length; i++) \r
                        {\r
                                _xmlWriter.WriteStartElement(paramNames[i]);\r
-//                             bool specifyEncoding = false;\r
-//                             if(paramValues[i].GetType() != paramTypes[i]) specifyEncoding = true;\r
-                               SerializeComponent(paramValues[i], IsEncodingNeeded(paramValues[i], paramTypes[i]));\r
+                               SerializeComponent(paramValues[i], true);\r
                                _xmlWriter.WriteEndElement();\r
                        }\r
 \r
@@ -518,15 +515,9 @@ namespace System.Runtime.Serialization.Formatters.Soap {
                                return;\r
                        }\r
 \r
-                       if(obj is double)\r
-                               _xmlWriter.WriteString(((double)obj).ToString("R"));\r
-                       else if(obj is DateTime)\r
-                               _xmlWriter.WriteString(((DateTime)obj).ToString("s")\r
-                                       + ((DateTime)obj).ToString(".fffffffzzz"));\r
-                       else\r
-                               _xmlWriter.WriteString(obj.ToString());\r
+                       _xmlWriter.WriteString (SoapTypeMapper.GetXsdValue (obj));\r
                }\r
-\r
+               \r
                private void EncodeType(Type type) \r
                {\r
                        if(type == null) \r