Multiple bug fixed concerning internationalization and xml attributes.
see the ChangeLog
svn path=/trunk/mcs/; revision=23259
+2004-02-19 Jean-Marc Andre <jeanmarc.andre@cpe.fr>
+ * SoapFormatter.cs:
+ Forced the utilisation of CultureInfo("en-US") during
+ the serialization and deserialization because I got problems
+ with numeral and date format.
+
+ * SoapWriter.cs, SoapCommon.cs:
+ Bug fixed: XmlTextWriter.WriteAttributeString() was used
+ with its "namespace" parameter set to null whereas it shouldn't.
+
2003-12-22 Jean-Marc Andre <jeanmarc.andre@cpe.fr>
* SoapFormatterTest.cs:
Added unit test for the SerializationBinder property
public string prefix;\r
public string attributeName;\r
public string attributeValue;\r
+ public string nameSpace;\r
\r
public SoapAttributeStruct(string prefix, string attributeName, string attributeValue) {\r
this.prefix = prefix;\r
this.attributeName = attributeName;\r
this.attributeValue = attributeValue;\r
+ this.nameSpace = null;\r
+ }\r
+\r
+ public SoapAttributeStruct(string prefix, string nameSpace, string attributeName, string attributeValue) {\r
+ this.prefix = prefix;\r
+ this.attributeName = attributeName;\r
+ this.attributeValue = attributeValue;\r
+ this.nameSpace = nameSpace;\r
}\r
}\r
\r
using System.Runtime.Serialization;\r
using System.Runtime.Remoting.Messaging;\r
using System.Xml.Serialization;\r
+using System.Threading;\r
+using System.Globalization;\r
\r
\r
namespace System.Runtime.Serialization.Formatters.Soap {\r
}\r
\r
public object Deserialize(Stream serializationStream, HeaderHandler handler) {\r
+ object objReturn = null;\r
SoapParser parser = new SoapParser(serializationStream);\r
SoapReader soapReader = new SoapReader(parser);\r
soapReader.Binder = _binder;\r
\r
- \r
if(_topObject != null) soapReader.TopObject = _topObject;\r
ObjectReader reader = new ObjectReader(_selector, _context, soapReader);\r
- parser.Run();\r
- object objReturn = reader.TopObject;\r
+ // Use the english numeral and date format during the serialization\r
+ // and the deserialization.\r
+ // The original CultureInfo is restored when the operation\r
+ // is done\r
+ CultureInfo savedCi = CultureInfo.CurrentCulture;\r
+ try {\r
+ Thread.CurrentThread.CurrentCulture = new CultureInfo("en-US");\r
+ parser.Run();\r
+ objReturn = reader.TopObject;\r
+ }\r
+ finally {\r
+ Thread.CurrentThread.CurrentCulture = savedCi;\r
+ }\r
return objReturn;\r
}\r
\r
_soapWriter = new SoapWriter(serializationStream);\r
_objWriter = new ObjectWriter((ISoapWriter) _soapWriter, _selector, new StreamingContext(StreamingContextStates.File));\r
_soapWriter.Writer = _objWriter;\r
- _objWriter.Serialize(graph);\r
+\r
+ // Use the english numeral and date format during the serialization\r
+ // and the deserialization.\r
+ // The original CultureInfo is restored when the operation\r
+ // is done\r
+ CultureInfo savedCi = CultureInfo.CurrentCulture;\r
+ try {\r
+ Thread.CurrentThread.CurrentCulture = new CultureInfo("en-US");\r
+ _objWriter.Serialize(graph);\r
+ }\r
+ finally {\r
+ Thread.CurrentThread.CurrentCulture = savedCi;\r
+ }\r
\r
}\r
\r
// If the type of the element needs to be specified, do it there\r
if(entry.SpecifyEncoding) {\r
needNamespace = GetPrefix(entry.elementNamespace, out prefix);\r
- attributeList.Add(new SoapAttributeStruct("xsi", "type", prefix+":"+ entry.elementName));\r
+ attributeList.Add(new SoapAttributeStruct("xsi", XmlSchema.InstanceNamespace, "type", prefix+":"+ entry.elementName));\r
if(needNamespace) attributeList.Add(new SoapAttributeStruct("xmlns", prefix, entry.elementNamespace));\r
}\r
\r
switch(entry.elementType) {\r
case ElementType.Null:\r
- attributeList.Add(new SoapAttributeStruct("xsi", "null", "1"));\r
+ attributeList.Add(new SoapAttributeStruct("xsi", XmlSchema.InstanceNamespace, "null", "1"));\r
return attributeList;\r
//break;\r
case ElementType.Id:\r
rank = rank.Substring(0,rank.Length - 1);\r
rank += "]";\r
needNamespace = GetPrefix(elementMapping.TypeNamespace, out prefix);\r
- attributeList.Add(new SoapAttributeStruct("SOAP-ENC", "arrayType",prefix+":"+elementMapping.TypeName+rank));\r
+ attributeList.Add(new SoapAttributeStruct("SOAP-ENC", "http://schemas.xmlsoap.org/soap/encoding/", "arrayType", prefix+":"+elementMapping.TypeName+rank));\r
if(needNamespace) attributeList.Add(new SoapAttributeStruct("xmlns", prefix, elementMapping.TypeNamespace));\r
\r
}\r
_xmlWriter.WriteStartElement(entry.prefix, XmlConvert.EncodeNmToken(entry.elementName), entry.elementNamespace);\r
\r
if (entry.elementAttributes != null) foreach(SoapAttributeStruct attr in entry.elementAttributes){\r
- _xmlWriter.WriteAttributeString(attr.prefix, attr.attributeName, null, attr.attributeValue);\r
+ _xmlWriter.WriteAttributeString(attr.prefix, attr.attributeName, attr.nameSpace, attr.attributeValue);\r
}\r
if(entry.CanBeValue && entry.elementValue != null && !entry.getIntoFields){\r
_xmlWriter.WriteString(String.Format(_format, "{0}", entry.elementValue));\r
public class MoreComplexObject {\r
public event TrucDlg TrucEvent;\r
private string _string;\r
+ private string[] _strings = new string[]{};\r
private Queue _queue = new Queue();\r
public Hashtable _table = new Hashtable();\r
\r
private SoapFormatter _soapFormatter;\r
private SoapFormatter _soapFormatterDeserializer;\r
private RemotingSurrogateSelector _surrogate;\r
+\r
+#if DEBUG\r
+ private void Out(MemoryStream stream, object objGraph) {\r
+ Console.WriteLine("\n---------------------\n{0}\n", objGraph.ToString());\r
+ stream.Position = 0;\r
+ StreamReader r = new StreamReader(stream);\r
+ Console.WriteLine(r.ReadToEnd());\r
+ } \r
+#endif\r
\r
private object Serialize(object objGraph) {\r
MemoryStream stream = new MemoryStream();\r
_soapFormatter.SurrogateSelector = _surrogate;\r
_soapFormatter.Serialize(stream, objGraph);\r
\r
-// stream.Position = 0;\r
-// StreamReader r = new StreamReader(stream);\r
-// Console.WriteLine(r.ReadToEnd());\r
+#if DEBUG\r
+ Out(stream, objGraph);\r
+#endif\r
stream.Position = 0;\r
\r
object objReturn = _soapFormatterDeserializer.Deserialize(stream);\r
stream = new MemoryStream();\r
_soapFormatter.Serialize(stream, objReturn);\r
stream.Position = 0;\r
-// StreamReader r = new StreamReader(stream);\r
-// Console.WriteLine(r.ReadToEnd());\r
- \r
return objReturn;\r
+ \r
}\r
\r
[SetUp]\r
objTest = new int[,]{{0, 1}, {2, 3}, {123, 4}};\r
objReturn = Serialize(objTest);\r
CheckArray(objTest, objReturn);\r
+ objTest = new string[]{};\r
+ objReturn = Serialize(objTest);\r
+ CheckArray(objTest, objReturn);\r
object[,,] objArray = new object[3,2,1];\r
objArray[0,0,0] = 1;\r
objArray[2,1,0] = "end";\r