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
+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
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
\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
{\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
{\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
}\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
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
{\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
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 {
}
-
+
+ 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);
+ }
+ }
}
}
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
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