Преглед на файлове

* SoapTypeMapper.cs: Added mappings for more primitive types.
* SoapWriter.cs: Use XmlSchema.Namespace and XmlSchema.InstanceNamespace
instead of string constants.

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

Lluis Sanchez преди 22 години
родител
ревизия
017e788ad7

+ 6 - 0
mcs/class/System.Runtime.Serialization.Formatters.Soap/ChangeLog

@@ -1,3 +1,9 @@
+2003-08-25  Lluis Sanchez Gual  <[email protected]>
+
+	* SoapTypeMapper.cs: Added mappings for more primitive types.
+	* SoapWriter.cs: Use XmlSchema.Namespace and XmlSchema.InstanceNamespace
+	  instead of string constants.
+
 2003-06-30  Jean-Marc Andre <[email protected]>
 	* SoapServices:
 		removed because it is now included in the

+ 30 - 46
mcs/class/System.Runtime.Serialization.Formatters.Soap/System.Runtime.Serialization.Formatters.Soap/SoapTypeMapper.cs

@@ -11,6 +11,7 @@ using System.Reflection;
 using System.Collections;
 using System.Runtime.Remoting;
 using System.Xml.Serialization;
+using System.Xml.Schema;
 
 namespace System.Runtime.Serialization.Formatters.Soap {
 	
@@ -26,7 +27,9 @@ namespace System.Runtime.Serialization.Formatters.Soap {
 		// returns the SoapTypeMapping corresponding to the System.Type
 		public static SoapTypeMapping GetSoapType(Type type) {
 			object rtnMapping;
-			
+
+			if (type.IsByRef) type = type.GetElementType ();
+
 			
 			if(type.IsArray){
 					rtnMapping = _mappingTable[typeof(System.Array)];
@@ -35,7 +38,6 @@ namespace System.Runtime.Serialization.Formatters.Soap {
 				rtnMapping = (object) _mappingTable[type];
 				
 				if(rtnMapping == null){
-					
 					string sTypeNamespace;
 					AssemblyName assName = type.Assembly.GetName();
 					if(assName.Name.StartsWith("mscorlib")) sTypeNamespace = "http://schemas.microsoft.com/clr/ns/"+type.Namespace;
@@ -79,6 +81,13 @@ namespace System.Runtime.Serialization.Formatters.Soap {
 			
 			return (Type)rtnObject;
 		}
+
+		private static void RegisterSchemaType (Type type, string typeName, bool canBeValue, bool isPrimitive,bool isValueType,bool needId)
+		{
+			SoapTypeMapping mapping =  new SoapTypeMapping (type, typeName, canBeValue, isPrimitive, isValueType, needId);
+			_mappingTable.Add(type, mapping);
+			_invertMappingTable.Add(mapping, type);
+		}
 		
 		// initialize the mapping tables
 		private static void InitMappingTable() {
@@ -88,51 +97,26 @@ namespace System.Runtime.Serialization.Formatters.Soap {
 			mapping =  new SoapTypeMapping(typeof(string), "string", true, false, false, true);
 			_mappingTable.Add(typeof(string),mapping);
 			_invertMappingTable.Add(mapping, typeof(string));
-			mapping =  new SoapTypeMapping(typeof(string), "string", "http://www.w3.org/2001/XMLSchema", true, false, false, true);
+			mapping =  new SoapTypeMapping(typeof(string), "string", XmlSchema.Namespace, true, false, false, true);
 			_invertMappingTable.Add(mapping, typeof(string));
-			
-			// the primitive type "System.Int16"
-			mapping =  new SoapTypeMapping(typeof(short), "short", "http://www.w3.org/2001/XMLSchema", true, true, true, false);
-			_mappingTable.Add(typeof(short), mapping);
-			_invertMappingTable.Add(mapping, typeof(short));
-			
-			// the primitive type "System.Int32"
-			mapping =  new SoapTypeMapping(typeof(int), "int", "http://www.w3.org/2001/XMLSchema", true, true, true, false);
-			_mappingTable.Add(typeof(int), mapping);
-			_invertMappingTable.Add(mapping, typeof(int));
-			
-			// the primitive type "System.Boolean"
-			mapping =  new SoapTypeMapping(typeof(bool), "boolean", "http://www.w3.org/2001/XMLSchema", true, true, true, false);
-			_mappingTable.Add(typeof(bool), mapping);
-			_invertMappingTable.Add(mapping, typeof(bool));
-			
-			// the primitive type "System.long"
-			mapping =  new SoapTypeMapping(typeof(long), "long", "http://www.w3.org/2001/XMLSchema", true, true, true, false);
-			_mappingTable.Add(typeof(long), mapping);
-			_invertMappingTable.Add(mapping, typeof(long));
-			
-			// the primitive type "System.double"
-			mapping =  new SoapTypeMapping(typeof(double), "double", "http://www.w3.org/2001/XMLSchema", true, true, true, false);
-			_mappingTable.Add(typeof(double), mapping);
-			_invertMappingTable.Add(mapping, typeof(double));
-			
-			// the primitive type "System.Char"
-			mapping =  new SoapTypeMapping(typeof(Char), "Char", "http://www.w3.org/2001/XMLSchema", true, true, true, false);
-			_mappingTable.Add(typeof(Char), mapping);
-			_invertMappingTable.Add(mapping, typeof(Char));
-			
-			// the primitive type "System.Single"
-			mapping = new SoapTypeMapping(typeof(System.Single), "float", "http://www.w3.org/2001/XMLSchema", true, true, true, false);
-			_mappingTable.Add(typeof(System.Single), mapping);
-			_invertMappingTable.Add(mapping, typeof(System.Single));
-			
-			mapping =  new SoapTypeMapping(typeof(System.Array), "Array", false, false, false, true);
-			_mappingTable.Add(typeof(System.Array), mapping);
-			_invertMappingTable.Add(mapping, typeof(System.Array));
-			
-			mapping = new SoapTypeMapping(typeof(object), "anyType", "http://www.w3.org/2001/XMLSchema", false, false, false, true);
-			_mappingTable.Add(typeof(object), mapping);
-			_invertMappingTable.Add(mapping, typeof(object));
+
+			RegisterSchemaType (typeof(short), "short", true, true, true, false);
+			RegisterSchemaType (typeof(ushort), "unsignedShort", true, true, true, false);
+			RegisterSchemaType (typeof(int), "int", true, true, true, false);
+			RegisterSchemaType (typeof(uint), "unsignedInt", true, true, true, false);
+			RegisterSchemaType (typeof(long), "long", true, true, true, false);
+			RegisterSchemaType (typeof(ulong), "unsignedLong", true, true, true, false);
+			RegisterSchemaType (typeof(decimal), "decimal", true, true, true, false);
+			RegisterSchemaType (typeof(sbyte), "byte", true, true, true, false);
+			RegisterSchemaType (typeof(byte), "unsignedByte", true, true, true, false);
+			RegisterSchemaType (typeof(DateTime), "dateTime", true, true, true, false);
+			RegisterSchemaType (typeof(TimeSpan), "duration", true, true, true, false);
+			RegisterSchemaType (typeof(double), "double", true, true, true, false);
+			RegisterSchemaType (typeof(Char), "char", true, true, true, false);
+			RegisterSchemaType (typeof(bool), "boolean", true, true, true, false);
+			RegisterSchemaType (typeof(System.Single), "float", true, true, true, false);
+			RegisterSchemaType (typeof(System.Array), "Array", false, false, false, true);
+			RegisterSchemaType (typeof(object), "anyType", false, false, false, true);
 			
 			mapping = new SoapTypeMapping(typeof(System.Runtime.Serialization.Formatters.SoapFault), "Fault", "http://schemas.xmlsoap.org/soap/envelope/", false, false, false, true);
 			_mappingTable.Add(typeof(System.Runtime.Serialization.Formatters.SoapFault), mapping);

+ 6 - 3
mcs/class/System.Runtime.Serialization.Formatters.Soap/System.Runtime.Serialization.Formatters.Soap/SoapWriter.cs

@@ -14,6 +14,7 @@ using System.Runtime.Remoting;
 using System.Runtime.Serialization;
 using System.Runtime.Serialization.Formatters;
 using System.Xml;
+using System.Xml.Schema;
 using System.Xml.Serialization;
 using System.Globalization;
 
@@ -107,6 +108,7 @@ namespace System.Runtime.Serialization.Formatters.Soap {
 				soapEntry.elementType = ElementType.Id;
 				_objectIds[objValue] = id;
 			}
+
 			
 			return soapEntry;
 		}
@@ -235,7 +237,7 @@ namespace System.Runtime.Serialization.Formatters.Soap {
 			}
 			
 		}
-		
+
 		private void WriteElement(SoapSerializationEntry entry) {
 			_xmlWriter.WriteStartElement(entry.prefix, XmlConvert.EncodeNmToken(entry.elementName), entry.elementNamespace);
 			
@@ -258,6 +260,7 @@ namespace System.Runtime.Serialization.Formatters.Soap {
 			Done = DoneWithElementEvent;
 			SoapSerializationEntry entry = FillEntry(rootType, rootValue); //new SoapSerializationEntry();
 			if(rootType.IsArray) {
+
 				Done = DoneWithArray;
 				entry.IsArray = true;
 			}
@@ -305,8 +308,8 @@ namespace System.Runtime.Serialization.Formatters.Soap {
 			ArrayList lstAttr = new ArrayList();
 			_xmlWriter.WriteStartElement("SOAP-ENV", "Envelope",  "http://schemas.xmlsoap.org/soap/envelope/");
 			
-			_xmlWriter.WriteAttributeString("xmlns", "xsi", null, "http://www.w3.org/2001/XMLSchema-instance");
-			_xmlWriter.WriteAttributeString("xmlns", "xsd", null, "http://www.w3.org/2001/XMLSchema" );
+			_xmlWriter.WriteAttributeString("xmlns", "xsi", null, XmlSchema.InstanceNamespace);
+			_xmlWriter.WriteAttributeString("xmlns", "xsd", null, XmlSchema.Namespace );
 			_xmlWriter.WriteAttributeString("xmlns", "SOAP-ENC", null, "http://schemas.xmlsoap.org/soap/encoding/");
 			_xmlWriter.WriteAttributeString("xmlns", "SOAP-ENV", null, "http://schemas.xmlsoap.org/soap/envelope/");
 			_xmlWriter.WriteAttributeString("xmlns", "clr", null, "http://schemas.microsoft.com/soap/encoding/clr/1.0" );