* SoapReader.cs: Serialize byte arrays using base64 encoding.
authorLluis Sanchez <lluis@novell.com>
Tue, 24 Aug 2004 14:36:07 +0000 (14:36 -0000)
committerLluis Sanchez <lluis@novell.com>
Tue, 24 Aug 2004 14:36:07 +0000 (14:36 -0000)
  GetComponentType should always return the type if
  specified, GetId can now be !=0 for base64 arrrays.
* SoapTypeMapper.cs: Register byte[] as base64 xml type.
* SoapWriter.cs: Handle base64 encoded byte arrays.

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

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 fac7bdc2e01ecd607cb65adfbfff06fc1ae629dc..e29ae99206d1aa8473de6910c0179a0603be29ed 100644 (file)
@@ -1,3 +1,11 @@
+2004-08-24  Lluis Sanchez Gual <lluis@ximian.com>
+
+       * SoapReader.cs: Serialize byte arrays using base64 encoding.
+         GetComponentType should always return the type if
+         specified, GetId can now be !=0 for base64 arrrays.
+       * SoapTypeMapper.cs: Register byte[] as base64 xml type.
+       * SoapWriter.cs: Handle base64 encoded byte arrays.
+
 2004-06-10  Lluis Sanchez Gual <lluis@ximian.com>
 
        * SoapWriter.cs: In SerializeArray, consider 1 a valid id.
index 69ff966dbb2f9f4c6806bfb3589a8f09a54b8a00..58d398c0555ee16a342a28c7e56e6b93fd07d6f8 100755 (executable)
@@ -193,10 +193,12 @@ namespace System.Runtime.Serialization.Formatters.Soap {
                private Type GetComponentType()\r
                {\r
                        Type type = null;\r
-                       if(GetId() != 0) return typeof(string);\r
                        \r
                        string strValue = xmlReader["type", XmlSchema.InstanceNamespace];\r
-                       if(strValue == null) return null;\r
+                       if(strValue == null) {\r
+                               if(GetId() != 0) return typeof(string);\r
+                               return null;\r
+                       }\r
                        string[] strName = strValue.Split(':');\r
                        string namespaceURI = xmlReader.LookupNamespace(strName[0]);\r
                        type = mapper[new Element(string.Empty, strName[1], namespaceURI)];\r
@@ -325,6 +327,13 @@ namespace System.Runtime.Serialization.Formatters.Soap {
                \r
                private object DeserializeArray(long id)\r
                {\r
+                       // Special case for base64 byte arrays\r
+                       if (GetComponentType () == typeof(byte[])) {\r
+                               byte[] data = Convert.FromBase64String (xmlReader.ReadElementString());\r
+                               RegisterObject(id, data, null, 0, null, null);\r
+                               return data;\r
+                       }\r
+                       \r
                        // Get the array properties\r
                        string strArrayType = xmlReader["arrayType", SoapTypeMapper.SoapEncodingNamespace];\r
                        string[] arrayInfo = strArrayType.Split(':','[',',',']');\r
@@ -350,13 +359,11 @@ namespace System.Runtime.Serialization.Formatters.Soap {
                                indices[i] = array.GetLowerBound(i);\r
                        }\r
 \r
-\r
                        // Deserialize the array items\r
                        int arrayDepth = xmlReader.Depth;\r
                        xmlReader.Read();\r
                        while(xmlReader.Depth > arrayDepth)\r
                        {\r
-\r
                                Type itemType = GetComponentType();\r
                                if(itemType == null) \r
                                        itemType = array.GetType().GetElementType();\r
index 5d788741e648e6d186ffdcf59acf08b6ca590423..0df2dae2348566f733c61991ca5c1eb854d319c0 100644 (file)
@@ -359,7 +359,10 @@ namespace System.Runtime.Serialization.Formatters.Soap {
                        xmlNodeToTypeTable.Add(element, elementType.AssemblyQualifiedName);
                        typeToXmlNodeTable.Add(elementType.AssemblyQualifiedName, element);
 
-
+                       element = new Element("base64", SoapEncodingNamespace);
+                       elementType = typeof(byte[]);
+                       xmlNodeToTypeTable.Add(element, elementType.AssemblyQualifiedName);
+                       typeToXmlNodeTable.Add(elementType.AssemblyQualifiedName, element);
                }
                
                public static string GetXsdValue (object value)
index 34b648e495866db7a775422b19a811524fb1a8c5..9cab0416153df3a6cab128700539cffe64a67933 100755 (executable)
@@ -448,6 +448,13 @@ namespace System.Runtime.Serialization.Formatters.Soap {
                        Element xmlArrayType = _mapper[arrayType];\r
                        _xmlWriter.WriteStartElement(element.Prefix, element.LocalName, element.NamespaceURI);\r
                        if(currentArrayId > 0) Id(currentArrayId);\r
+                       \r
+                       if (arrayType == typeof(byte)) {\r
+                               EncodeType (currentArray.GetType());\r
+                               _xmlWriter.WriteString (Convert.ToBase64String ((byte[])currentArray));\r
+                               _xmlWriter.WriteFullEndElement();\r
+                               return;\r
+                       }\r
 \r
                        if(_xmlWriter.LookupPrefix(xmlArrayType.NamespaceURI) == null)\r
                        {\r