2003-05-27 Jean-Marc Andre <jean-marc.andre@polymtl.ca>
authorJean-Marc Andre <jeanmarc@mono-cvs.ximian.com>
Wed, 28 May 2003 00:25:04 +0000 (00:25 -0000)
committerJean-Marc Andre <jeanmarc@mono-cvs.ximian.com>
Wed, 28 May 2003 00:25:04 +0000 (00:25 -0000)
Bugs fixed
Preparing the SoapFormatter for remoting

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

12 files changed:
mcs/class/System.Runtime.Serialization.Formatters.Soap/ChangeLog
mcs/class/System.Runtime.Serialization.Formatters.Soap/System.Runtime.Serialization.Formatters.Soap.build
mcs/class/System.Runtime.Serialization.Formatters.Soap/System.Runtime.Serialization.Formatters.Soap/ISoapReader.cs
mcs/class/System.Runtime.Serialization.Formatters.Soap/System.Runtime.Serialization.Formatters.Soap/ObjectReader.cs
mcs/class/System.Runtime.Serialization.Formatters.Soap/System.Runtime.Serialization.Formatters.Soap/ObjectWriter.cs
mcs/class/System.Runtime.Serialization.Formatters.Soap/System.Runtime.Serialization.Formatters.Soap/SoapFormatter.cs
mcs/class/System.Runtime.Serialization.Formatters.Soap/System.Runtime.Serialization.Formatters.Soap/SoapFormatter.prjx
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
mcs/class/System.Runtime.Serialization.Formatters.Soap/Test/SoapFormatterTest.cs
mcs/class/System.Runtime.Serialization.Formatters.Soap/Test/Test.prjx

index d69c7244dae555412f3eec2781b44259ddec31d3..4880087143ddcc9dd3817dfa4c5c3a4dba9455e9 100644 (file)
@@ -1,3 +1,9 @@
+2003-05-27  Jean-Marc Andre <jean-marc.andre@polymtl.ca>
+       * SoapWriter:
+               bugs fixed
+       * SoapFormatter:
+               preparing for the remoting
+
 2003-05-15  Jean-Marc Andre <jean-marc.andre@polymtl.ca>
        * SoapFormatter:
                New version of the SoapFormatter installed
index 4bb81e0d2b1804c6c4b159ea783c58995384d92a..b9116d7e302ce015cb8b260da57802b9dc16ef89 100755 (executable)
@@ -28,7 +28,7 @@
                </csc>
                <copy file="../lib/System.Runtime.Serialization.Formatters.Soap.dll" tofile="Test/System.Runtime.Serialization.Formatters.Soap.dll"/>
                <!--copy file="../lib/System.Xml.dll" tofile="Test/System.Xml.dll"/-->
-               <nant basedir="Test" target="build"/>
+               <!--nant basedir="Test" target="build"/-->
        </target>
 
        <target name="test" depends="build">
index c2868cfff51274fb1c3d42cefb996c320ee69991..8ce82836b0db5fb80cb2dd7bf21deb9671a13ef8 100644 (file)
@@ -14,5 +14,8 @@ namespace System.Runtime.Serialization.Formatters.Soap {
        \r
        internal interface ISoapReader {\r
                event ElementReadEventHandler ElementReadEvent;\r
+               ISoapMessage TopObject {\r
+                       get; set;\r
+               }\r
        }\r
 }\r
index 64fedd8fe102457171865658ba35cc9ac56c2651..d953ae9ecabfd825f139bc95d1bf29f37d5b35d9 100644 (file)
@@ -9,6 +9,7 @@
 using System;\r
 using System.Collections;\r
 using System.Reflection;\r
+using System.Runtime.Remoting;\r
 using System.Runtime.Serialization;\r
 \r
 namespace System.Runtime.Serialization.Formatters.Soap {\r
@@ -44,6 +45,11 @@ namespace System.Runtime.Serialization.Formatters.Soap {
                        return Int64.MaxValue ^ ++_nonId;\r
                }\r
                \r
+               // sometimes, the root object doesn't have an id\r
+               // An id has to be created to register the object\r
+               // with the ObjectManager\r
+               // If the root object is a SoapMessage. It has to be handle\r
+               // in a different way\r
                public void RootElementRead(ISoapReader sender, ElementReadEventArgs e) {\r
                        ElementReadEventArgs args = e;\r
                        sender.ElementReadEvent -= new ElementReadEventHandler(RootElementRead);\r
@@ -54,8 +60,30 @@ namespace System.Runtime.Serialization.Formatters.Soap {
                                _topObjectId = rootInfo._i;\r
                        }\r
                        args.RootElement = rootInfo;\r
-                       ElementRead(sender, args);\r
+                       if(rootInfo._type == typeof(SoapMessage)) RPCHandler(args);\r
+                       else ElementRead(sender, args);\r
 \r
+               }\r
+               \r
+               private void RPCHandler(ElementReadEventArgs e) {\r
+                       ElementInfo rpcInfo = e.RootElement;\r
+                       SoapMessage soapMessage = (SoapMessage) rpcInfo._value;\r
+                       \r
+                       \r
+                       // register the SoapMessage\r
+                       _manager.RegisterObject(soapMessage, 1);\r
+                       \r
+                       int count = e.FieldsInfo.Count;\r
+                       soapMessage.ParamNames = new string[count];\r
+                       soapMessage.ParamTypes = new Type[count];\r
+                       soapMessage.ParamValues = new object[count];\r
+                       \r
+                       long paramValuesId = GetNextId();\r
+                       _manager.RegisterObject(soapMessage.ParamValues, paramValuesId);\r
+                       soapMessage.ParamNames = FixupArrayItems(paramValuesId, e.FieldsInfo);\r
+                       \r
+                       \r
+                       \r
                }\r
                \r
                public void ElementRead(ISoapReader sender, ElementReadEventArgs e) {\r
@@ -74,7 +102,7 @@ namespace System.Runtime.Serialization.Formatters.Soap {
                        _manager.RegisterObject(objRoot, rootInfo._i, serializationInfo);\r
                        \r
                        if(objRoot.GetType().IsArray){\r
-                               FixupArrayItems(rootInfo._i, rootInfo._arrayDims, e.FieldsInfo);\r
+                               FixupArrayItems(rootInfo._i, e.FieldsInfo);\r
                        }else {\r
                                FixupFields(rootInfo._i, objRoot, rootInfo._type, e.FieldsInfo, serializationInfo);\r
                        }\r
@@ -128,7 +156,6 @@ namespace System.Runtime.Serialization.Formatters.Soap {
                                                        memberInfo.SetValue(objectToBeFixed, objValue, BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic, null, null);\r
                                                }\r
                                                _manager.RegisterObject(objValue, fieldInfo._i, null, objectToBeFixedId, memberInfo);\r
-//                                             _manager.DoFixups();\r
                                                break;\r
                                        case ElementType.Nothing:\r
                                                if(serializationInfo != null) {\r
@@ -162,9 +189,10 @@ namespace System.Runtime.Serialization.Formatters.Soap {
                        }\r
                }\r
                \r
-               private void FixupArrayItems(long arrayToBeFixedId, int[] arrayDims, ICollection arrayItemsInfo) {\r
+               private String[] FixupArrayItems(long arrayToBeFixedId, ICollection arrayItemsInfo) {\r
+                       ArrayList arrayNames = new ArrayList(arrayItemsInfo.Count);\r
                        System.Array array = (System.Array) _manager.GetObject(arrayToBeFixedId);\r
-                       if(array.Length == 0) return;\r
+//                     if(array.Length == 0) return null;\r
                        int[] indices = new int[array.Rank];\r
                        for(int dim=array.Rank-1; dim>=0; dim--){\r
                                indices[dim] = array.GetLowerBound(dim);\r
@@ -175,6 +203,7 @@ namespace System.Runtime.Serialization.Formatters.Soap {
                        IEnumerator iEnum = arrayItemsInfo.GetEnumerator();\r
                        while(iEnum.MoveNext()) {\r
                                ElementInfo arrayItemInfo = (ElementInfo) iEnum.Current;\r
+                               arrayNames.Add(arrayItemInfo._name);\r
                                specificElementType = (arrayItemInfo._type != null) ? arrayItemInfo._type : arrayElementType;\r
                                switch(arrayItemInfo._elementType) {\r
                                        case ElementType.Href:\r
@@ -207,7 +236,8 @@ namespace System.Runtime.Serialization.Formatters.Soap {
                                }\r
                                bool end = FillIndices(array, ref indices);\r
                        }\r
-                       \r
+                       string[] aNames = (string[]) arrayNames.ToArray(typeof(string));\r
+                       return aNames;\r
                }\r
                \r
                private bool FillIndices(System.Array array, ref int[] indices) {\r
index cea47c990f3b395b6a5a584cf28b9b4c4f145ce9..87ac66f9401da49fc72475cb6ae75224857cef2a 100644 (file)
@@ -52,7 +52,7 @@ namespace System.Runtime.Serialization.Formatters.Soap {
                                }\r
                        }\r
                        ISerializable ser = objCurrent as ISerializable;\r
-                       if(ser != null){\r
+                       if(ser != null && _serializationInfo.MemberCount == 0){\r
                                ser.GetObjectData(_serializationInfo, _context);\r
                        }\r
                        if(_serializationInfo.MemberCount == 0) {\r
index e9b1dfb0ac81a1232f0025d0650cdc039ad858ff..0317abbf9a05cb1557fa8f7ccca090d46658cfe0 100755 (executable)
@@ -8,28 +8,36 @@
 \r
 using System;\r
 using System.IO;\r
+using System.Reflection;\r
+using System.Runtime.Remoting;\r
 using System.Runtime.Serialization;\r
 using System.Runtime.Remoting.Messaging;\r
 using System.Xml.Serialization;\r
 \r
 \r
 namespace System.Runtime.Serialization.Formatters.Soap {\r
-       public class SoapFormatterT: IRemotingFormatter, IFormatter {\r
+       enum RemMessageType {\r
+               MethodCall, MethodResponse, ServerFault, NotRecognize\r
+       }\r
+       \r
+       public class SoapFormatter: IRemotingFormatter, IFormatter {\r
                private ObjectWriter _objWriter;\r
                private SoapWriter _soapWriter;\r
                private SerializationBinder _binder;\r
                private StreamingContext _context;\r
                private ISurrogateSelector _selector;\r
+               private ISoapMessage _topObject;\r
                \r
-               public SoapFormatterT() {\r
+               public SoapFormatter() {\r
+                       \r
                }\r
                \r
-               public SoapFormatterT(ISurrogateSelector selector, StreamingContext context):this() {\r
+               public SoapFormatter(ISurrogateSelector selector, StreamingContext context):this() {\r
                        _selector = selector;\r
                        _context = context;\r
                }\r
                \r
-               ~SoapFormatterT() {\r
+               ~SoapFormatter() {\r
                }\r
                \r
                public object Deserialize(Stream serializationStream) {\r
@@ -39,12 +47,18 @@ namespace System.Runtime.Serialization.Formatters.Soap {
                public object Deserialize(Stream serializationStream, HeaderHandler handler) {\r
                        SoapParser parser = new SoapParser(serializationStream);\r
                        SoapReader soapReader = new SoapReader(parser);\r
+                       \r
+                       \r
+                       if(_topObject != null) soapReader.TopObject = _topObject;\r
                        ObjectReader reader = new ObjectReader(_selector, _context, soapReader);\r
                        parser.Run();\r
-                       return reader.TopObject;\r
+                       object objReturn = reader.TopObject;\r
+                       if(objReturn is SoapMessage) FixupSoapMessage((SoapMessage)objReturn);\r
+                       return objReturn;\r
                }\r
                \r
                \r
+               \r
                public void Serialize(Stream serializationStream, object graph) {\r
                        Serialize(serializationStream, graph, null);\r
                }\r
@@ -89,5 +103,120 @@ namespace System.Runtime.Serialization.Formatters.Soap {
                        }\r
                }\r
                \r
+               public ISoapMessage TopObject {\r
+                       get {\r
+                               return _topObject;\r
+                       }\r
+                       set {\r
+                               _topObject = value;\r
+                       }\r
+               }\r
+               \r
+       \r
+               //private methods\r
+               \r
+               // finish the work on the SoapMessage\r
+               // fill the SoapMessage.ParamName array\r
+               // fill the SoapMessage.ParamType array\r
+               // convert the SoapMessage.ParamValue array items\r
+               // to the right type if needed\r
+               private void FixupSoapMessage(ISoapMessage msg) {\r
+                       string typeNamespace, assemblyName;\r
+                       \r
+                       SoapServices.DecodeXmlNamespaceForClrTypeNamespace(msg.XmlNameSpace, out typeNamespace, out assemblyName);\r
+                       try{\r
+                               RemMessageType messageType;\r
+                               MethodInfo mi = GetMethodInfo(msg.MethodName, msg.XmlNameSpace, out messageType);\r
+                               \r
+                               FormatterConverter conv = new FormatterConverter();\r
+                               switch(messageType) {\r
+                                       case RemMessageType.MethodCall:\r
+                                               int nbOutParams = 0;\r
+                                               ParameterInfo[] paramInfo = mi.GetParameters();\r
+                                               foreach(ParameterInfo param in paramInfo) {\r
+                                                       // The *out* parameters aren't serialized\r
+                                                       if(!param.IsOut) {\r
+                                                               msg.ParamNames[param.Position - nbOutParams] = param.Name;\r
+                                                               msg.ParamTypes[param.Position - nbOutParams] = param.ParameterType;\r
+                                                               if(msg.ParamValues[param.Position - nbOutParams] is IConvertible) msg.ParamValues[param.Position - nbOutParams] = conv.Convert(msg.ParamValues[param.Position - nbOutParams], param.ParameterType);\r
+                                                       }\r
+                                                       else nbOutParams++;\r
+                                               }\r
+                                               break;\r
+                                       case RemMessageType.MethodResponse:\r
+                                               int offset = 0;\r
+                                               if(mi.ReturnType != typeof(void)) {\r
+                                                       msg.ParamNames[0] = "return";\r
+                                                       msg.ParamTypes[0] = mi.ReturnType;\r
+                                                       if(msg.ParamValues[0] is IConvertible) msg.ParamValues[0] = Convert.ChangeType(msg.ParamValues[0], mi.ReturnType);\r
+                                                       offset++;\r
+                                               }\r
+                                               paramInfo = mi.GetParameters();\r
+                                               foreach(ParameterInfo param in paramInfo) {\r
+                                                       // The *out* parameters\r
+                                                       if(param.IsOut) {\r
+                                                               msg.ParamNames[offset] = param.Name;\r
+                                                               //msg.ParamTypes[offset] = param.ParameterType;\r
+                                                               //if(msg.ParamValues[offset] is IConvertible) msg.ParamValues[param.Position] = conv.Convert(msg.ParamValues[offset], param.ParameterType);\r
+                                                               offset++;\r
+                                                       }\r
+                                               }\r
+                                               break;\r
+                                       case RemMessageType.ServerFault:\r
+                                               break;\r
+                                       case RemMessageType.NotRecognize:\r
+                                                throw new SerializationException(String.Format("Can't find a method with name {0} for {1}", msg.MethodName, msg.XmlNameSpace));\r
+                                       \r
+                               }\r
+                       }\r
+                       catch(Exception e) {\r
+                               // Last chance\r
+                               // maybe it is a SoapFault object\r
+                               if(msg.MethodName != "Fault") throw new SerializationException("Don't understand the response from the server");\r
+                               else return;\r
+                       }\r
+                       \r
+               }\r
+               \r
+               // Get the MethodInfo\r
+               internal static MethodInfo GetMethodInfo(string methodName, string xmlNamespace, out RemMessageType messageType) {\r
+                       string typeNamespace, assemblyName;\r
+                       bool result = SoapServices.DecodeXmlNamespaceForClrTypeNamespace(xmlNamespace, out typeNamespace, out assemblyName);\r
+                       return GetMethodInfo(methodName, typeNamespace, assemblyName, out messageType);\r
+               }\r
+               \r
+               internal static MethodInfo GetMethodInfo(string methodName, string typeName, string assemblyName, out RemMessageType messageType) {\r
+                       Type type = GetType(typeName, assemblyName);\r
+                       MethodInfo mi = null;\r
+                       messageType = RemMessageType.MethodCall;\r
+                       if(type != null) {\r
+                               mi = type.GetMethod(methodName);\r
+                               \r
+                               if(mi == null) {\r
+                                       int index = methodName.LastIndexOf("Response");\r
+                                       string methodResponseName = methodName.Remove(index, methodName.Length - index);\r
+                                       mi = type.GetMethod(methodResponseName);\r
+                                       if(mi == null) {\r
+                                               if(methodName != "Fault") messageType = RemMessageType.NotRecognize;\r
+                                               else messageType = RemMessageType.ServerFault;\r
+                                       } \r
+                                       messageType = RemMessageType.MethodResponse;\r
+                               }\r
+                       }\r
+                       return mi;\r
+               }\r
+               \r
+               internal static Type GetType(string typeName, string assemblyName) {\r
+                       Type type = Type.GetType(typeName);\r
+                       if(type == null) {\r
+                               AssemblyName assName = new AssemblyName();\r
+                               assName.Name = assemblyName;\r
+                               Assembly ass = Assembly.Load(assName);\r
+                               type = FormatterServices.GetTypeFromAssembly(ass, typeName);\r
+                               if(type == null) throw new SerializationException(String.Format("Can't find type {0} in assembly {1}", typeName, assemblyName));\r
+                       }\r
+                       return type;\r
+               }\r
+               \r
        }\r
 }\r
index bffaa21ae6c11755f21cd1ebcd5579808ba67d5d..48fddca5161351aed742f7e6ab24f7aa439901bc 100644 (file)
     <File name=".\SoapReader.cs" subtype="Code" buildaction="Compile" dependson="" data="" />\r
     <File name=".\SoapTypeMapper.cs" subtype="Code" buildaction="Compile" dependson="" data="" />\r
     <File name=".\SoapTypeMapping.cs" subtype="Code" buildaction="Compile" dependson="" data="" />\r
-    <File name=".\ObjectManager.cs" subtype="Code" buildaction="Compile" dependson="" data="" />\r
+    <File name=".\ObjectManager.cs" subtype="Code" buildaction="Nothing" dependson="" data="" />\r
   </Contents>\r
   <References />\r
   <DeploymentInformation target="" script="" strategy="File" />\r
   <Configuration runwithwarnings="True" name="Debug">\r
     <CodeGeneration runtime="MsNet" compiler="Csc" warninglevel="0" includedebuginformation="True" optimize="True" unsafecodeallowed="True" generateoverflowchecks="True" mainclass="" target="Library" definesymbols="" generatexmldocumentation="False" win32Icon="" />\r
     <Execution commandlineparameters="" consolepause="False" />\r
-    <Output directory="..\" assembly="Soap" />\r
+    <Output directory="..\..\..\..\..\..\..\..\Jim\SharpDevelop Projects\MySinks" assembly="Soap" />\r
   </Configuration>\r
   <Configurations active="Debug">\r
     <Configuration runwithwarnings="True" name="Debug">\r
       <CodeGeneration runtime="MsNet" compiler="Csc" warninglevel="0" includedebuginformation="True" optimize="True" unsafecodeallowed="True" generateoverflowchecks="True" mainclass="" target="Library" definesymbols="" generatexmldocumentation="False" win32Icon="" />\r
       <Execution commandlineparameters="" consolepause="False" />\r
-      <Output directory="..\" assembly="Soap" />\r
+      <Output directory="..\..\..\..\..\..\..\..\Jim\SharpDevelop Projects\MySinks" assembly="Soap" />\r
     </Configuration>\r
     <Configuration runwithwarnings="True" name="Release">\r
       <CodeGeneration runtime="MsNet" compiler="Csc" warninglevel="0" includedebuginformation="False" optimize="True" unsafecodeallowed="True" generateoverflowchecks="False" mainclass="" target="Library" definesymbols="" generatexmldocumentation="False" win32Icon="" />\r
index e8c1ac71b562ec3463ae82fcf777d909dc12fc3a..d60b7dbd503e449dec6423eba95ae5c43a6b5806 100755 (executable)
@@ -14,10 +14,62 @@ using System.Runtime.Serialization;
 namespace System.Runtime.Serialization.Formatters.Soap {\r
        internal class SoapReader: ISoapReader {\r
                public event ElementReadEventHandler ElementReadEvent;\r
+               private ISoapMessage _soapMessage;\r
+               private ISoapParser _parser;\r
+               \r
+               public ISoapMessage TopObject {\r
+                       get { return _soapMessage; }\r
+                       set { \r
+                               _soapMessage = value;\r
+                               \r
+                               // the first element of the SOAP stream\r
+                               // should be a SOAP RPC\r
+                               _parser.SoapElementReadEvent -= new SoapElementReadEventHandler(SoapElementRead);\r
+                               _parser.SoapElementReadEvent += new SoapElementReadEventHandler(SoapRPCElementRead);\r
+                       }\r
+               }\r
                \r
                public SoapReader(ISoapParser parser) {\r
                        // register the SoapElementReadEvent handler\r
-                       parser.SoapElementReadEvent += new SoapElementReadEventHandler(SoapElementRead);\r
+                       _parser = parser;\r
+                       _parser.SoapElementReadEvent += new SoapElementReadEventHandler(SoapElementRead);\r
+               }\r
+               \r
+               public void SoapRPCElementRead(ISoapParser sender, SoapElementReadEventArgs e) {\r
+                       _parser.SoapElementReadEvent += new SoapElementReadEventHandler(SoapElementRead);\r
+                       _parser.SoapElementReadEvent -= new SoapElementReadEventHandler(SoapRPCElementRead);\r
+                       \r
+                       Queue elementQueue = e.ElementQueue;\r
+                       Queue elementInfoQueue = new Queue();\r
+                       SoapSerializationEntry root = (SoapSerializationEntry) elementQueue.Dequeue();\r
+                       \r
+                       // fill the SoapMessage members\r
+                       // MethodName\r
+                       //elementInfoQueue.Enqueue(new ElementInfo(typeof(string), "MethodName", rpcInfo.elementName, ElementType.Nothing, 0, 0);\r
+                       _soapMessage.MethodName = root.elementName;\r
+                       \r
+                       // XmlNamespace\r
+                       //elementInfoQueue.Enqueue(new ElementInfo(typeof(string), "XmlNamespace", rpcInfo.elementNamespace, ElementType.Nothing, 0, 0);\r
+                       _soapMessage.XmlNameSpace = root.elementNamespace;\r
+                       \r
+                       // the root element is a SoapMessage\r
+                       ElementInfo rpcInfo = new ElementInfo(typeof(SoapMessage), String.Empty, _soapMessage, ElementType.Id, 1, null);\r
+                       \r
+                       //todo: headers\r
+                       \r
+                       // add the function parameters to the queue\r
+                       SoapSerializationEntry field;\r
+                       ElementInfo fieldElementInfo;\r
+                       while(elementQueue.Count > 0){\r
+                               field = (SoapSerializationEntry) elementQueue.Dequeue();\r
+                               fieldElementInfo = GetElementInfo(field);\r
+                               elementInfoQueue.Enqueue(fieldElementInfo);\r
+                       }\r
+\r
+                       // raise the ElementReadEvent\r
+                       ElementReadEvent(this,new ElementReadEventArgs(rpcInfo, elementInfoQueue));\r
+                       \r
+                       \r
                }\r
                \r
                // called when SoapElementReadEvent is raized by the SoapParser object\r
@@ -28,9 +80,11 @@ namespace System.Runtime.Serialization.Formatters.Soap {
                        \r
                        ElementInfo rootInfo = GetElementInfo(root);\r
                        SoapSerializationEntry field;\r
+                       ElementInfo fieldElementInfo;\r
                        while(elementQueue.Count > 0){\r
                                field = (SoapSerializationEntry) elementQueue.Dequeue();\r
-                               elementInfoQueue.Enqueue(GetElementInfo(field));\r
+                               fieldElementInfo = GetElementInfo(field);\r
+                               elementInfoQueue.Enqueue(fieldElementInfo);\r
                        }\r
 \r
                        // raise the ElementReadEvent\r
index a456835753ebde3183dab58df2004197da7fa5b6..e5c9da532ead5d949d62e30bd15b04d8b01375be 100644 (file)
@@ -68,7 +68,9 @@ namespace System.Runtime.Serialization.Formatters.Soap {
                                rtnObject = Type.GetType(typeNamespace+"."+mapping.TypeName);\r
                                \r
                                if(rtnObject == null) {\r
-                                       Assembly ass =Assembly.Load(typeNamespace);\r
+//                                     AssemblyName assName = new AssemblyName()\r
+//                                     assName.FullName = asse\r
+                                       Assembly ass =Assembly.Load(assemblyName);\r
                                        if(ass != null) {\r
                                                rtnObject = ass.GetType(typeNamespace+"."+mapping.TypeName, true);\r
                                        }\r
@@ -86,6 +88,8 @@ namespace System.Runtime.Serialization.Formatters.Soap {
                        mapping =  new SoapTypeMapping(typeof(string), "string", true, false, false, true);\r
                        _mappingTable.Add(typeof(string),mapping);\r
                        _invertMappingTable.Add(mapping, typeof(string));\r
+                       mapping =  new SoapTypeMapping(typeof(string), "string", "http://www.w3.org/2001/XMLSchema", true, false, false, true);\r
+                       _invertMappingTable.Add(mapping, typeof(string));\r
                        \r
                        // the primitive type "System.Int16"\r
                        mapping =  new SoapTypeMapping(typeof(short), "short", "http://www.w3.org/2001/XMLSchema", true, true, true, false);\r
@@ -130,6 +134,10 @@ namespace System.Runtime.Serialization.Formatters.Soap {
                        _mappingTable.Add(typeof(object), mapping);\r
                        _invertMappingTable.Add(mapping, typeof(object));\r
                        \r
+                       mapping = new SoapTypeMapping(typeof(System.Runtime.Serialization.Formatters.SoapFault), "Fault", "http://schemas.xmlsoap.org/soap/envelope/", false, false, false, true);\r
+                       _mappingTable.Add(typeof(System.Runtime.Serialization.Formatters.SoapFault), mapping);\r
+                       _invertMappingTable.Add(mapping, typeof(System.Runtime.Serialization.Formatters.SoapFault));\r
+                       \r
                        \r
                }\r
        }\r
index ec0344f3b0b65c5400c1d80de629461d28153eb6..61d1b194fd533909e4bae0920556a0bfcb53b04c 100755 (executable)
@@ -56,6 +56,7 @@ namespace System.Runtime.Serialization.Formatters.Soap {
                        // todo: manage the encoding\r
                        _xmlWriter = new XmlTextWriter(outStream, null);\r
                        _xmlWriter.Formatting = Formatting.Indented;\r
+                       _xmlWriter.Indentation = 2;\r
 //                     _xmlWriter.WriteComment("My serialization function");\r
                        _format = new CultureInfo("en-US");\r
                }\r
@@ -64,7 +65,6 @@ namespace System.Runtime.Serialization.Formatters.Soap {
                }\r
                \r
                private SoapSerializationEntry FillEntry(Type defaultObjectType, object objValue) {\r
-//                     SoapTypeMapping mapping = GetTagInfo((objValue != null)?objValue.GetType():defaultObjectType);\r
                        SoapTypeMapping mapping = GetTagInfo((objValue != null && defaultObjectType == typeof(object))?objValue.GetType():defaultObjectType);\r
                        \r
                        SoapSerializationEntry soapEntry = new SoapSerializationEntry();\r
@@ -89,6 +89,7 @@ namespace System.Runtime.Serialization.Formatters.Soap {
                                soapEntry.elementType = ElementType.Href;\r
                                soapEntry.i = (long) _objectIds[objValue];\r
                                soapEntry.WriteFullEndElement = false;\r
+                               soapEntry.SpecifyEncoding = false;\r
                        }\r
                        else if(!mapping.CanBeValue){\r
                                id = GetNextId();\r
@@ -98,6 +99,7 @@ namespace System.Runtime.Serialization.Formatters.Soap {
                                _objectQueue.Enqueue(new EnqueuedObject(objValue, id));\r
                                _objectRefs[id] = objValue;\r
                                _objectIds[objValue] = id;\r
+                               soapEntry.SpecifyEncoding = false;\r
                        } \r
                        else if(mapping.NeedId){ \r
                                id = GetNextId();\r
@@ -211,12 +213,10 @@ namespace System.Runtime.Serialization.Formatters.Soap {
                }\r
                \r
                public void WriteFields(SerializationInfo info) {\r
-               //      SoapTypeMapping mapping;\r
                        ICollection attributeList;\r
                        SoapSerializationEntry soapEntry;\r
                        \r
                        foreach(SerializationEntry entry in info){\r
-               //              mapping = GetTagInfo(entry.ObjectType);\r
                                soapEntry = FillEntry(entry.ObjectType, entry.Value);\r
                                \r
                                \r
@@ -336,7 +336,6 @@ namespace System.Runtime.Serialization.Formatters.Soap {
                }\r
                \r
                private void WriteSoapRPC(ISoapMessage soapMsg) {\r
-                       throw new NotImplementedException();\r
                        \r
                        _xmlWriter.WriteStartElement("i2", soapMsg.MethodName, soapMsg.XmlNameSpace);\r
                        _xmlWriter.WriteAttributeString("id", null, "ref-"+_currentObjectId);\r
@@ -346,12 +345,16 @@ namespace System.Runtime.Serialization.Formatters.Soap {
                        SoapServices.DecodeXmlNamespaceForClrTypeNamespace(soapMsg.XmlNameSpace, out typeNamespace, out assemblyName);\r
                        \r
                        Type objType = Type.GetType(typeNamespace);\r
-                       MethodInfo mthInfo = objType.GetMethod(soapMsg.MethodName);\r
-                       \r
-                       for(int i=0; i<soapMsg.ParamNames.Length; i++){\r
-                               info.AddValue(soapMsg.ParamNames[i], soapMsg.ParamValues[i], soapMsg.ParamTypes[i]);\r
+                       if(soapMsg.ParamNames != null) {\r
+                               for(int i=0; i<soapMsg.ParamNames.Length; i++){\r
+                                       string name = soapMsg.ParamNames[i];\r
+                                       object objValue = soapMsg.ParamValues[i];\r
+                                       Type type = soapMsg.ParamTypes[i];\r
+                                       info.AddValue(name, objValue, type);\r
+                               }\r
+                               WriteFields(info);\r
                        }\r
-                       WriteFields(info);\r
+                       \r
                        \r
                        _xmlWriter.WriteEndElement();\r
                        \r
index c82c80498888c8193c564ed741e4c2101c82ad45..ee166170f8effdc1ad134b8c7b0bd94e6b4c48aa 100644 (file)
@@ -1,8 +1,10 @@
 // project created on 09/05/2003 at 18:07\r
 using System;\r
 using System.Collections;\r
+using System.Runtime.Remoting;\r
 using System.Runtime.Remoting.Messaging;\r
 using System.Runtime.Serialization;\r
+using System.Runtime.Serialization.Formatters;\r
 using System.Runtime.Serialization.Formatters.Soap;\r
 using System.IO;\r
 using NUnit.Framework;\r
@@ -109,30 +111,40 @@ namespace MonoTests.System.Runtime.Serialization.Formatters.Soap {
        [TestFixture]\r
        public class SoapFormatterTest\r
        {\r
-               private SoapFormatterT _soapFormatter;\r
+               private SoapFormatter _soapFormatter;\r
+               private SoapFormatter _soapFormatterDeserializer;\r
+               private RemotingSurrogateSelector _surrogate;\r
                \r
                private object Serialize(object objGraph) {\r
                        MemoryStream stream = new MemoryStream();\r
+                       Assertion.Assert(objGraph != null);\r
+                       Assertion.Assert(stream != null);\r
+                       _soapFormatter.SurrogateSelector = _surrogate;\r
                        _soapFormatter.Serialize(stream, objGraph);\r
                        \r
-                       \r
+                       stream.Position = 0;\r
+                       StreamReader r = new StreamReader(stream);\r
+                       Console.WriteLine(r.ReadToEnd());\r
                        stream.Position = 0;\r
                        \r
-                       object objReturn = _soapFormatter.Deserialize(stream);\r
+                       object objReturn = _soapFormatterDeserializer.Deserialize(stream);\r
                        Assertion.Assert(objReturn != null);\r
                        Assertion.AssertEquals("#Tests "+objGraph.GetType(), objGraph.GetType(), objReturn.GetType());\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
+//                     StreamReader r = new StreamReader(stream);\r
+//                     Console.WriteLine(r.ReadToEnd());\r
                        \r
                        return objReturn;\r
                }\r
                \r
                [SetUp]\r
                public void GetReady() {\r
-                       _soapFormatter = new SoapFormatterT(new RemotingSurrogateSelector(), new StreamingContext(StreamingContextStates.All));\r
+                       StreamingContext context = new StreamingContext(StreamingContextStates.All);\r
+                       _surrogate = new RemotingSurrogateSelector();\r
+                       _soapFormatter = new SoapFormatter(_surrogate, context);\r
+                       _soapFormatterDeserializer = new SoapFormatter(null, context);\r
                }\r
                \r
                [TearDown]\r
@@ -166,6 +178,16 @@ namespace MonoTests.System.Runtime.Serialization.Formatters.Soap {
                        objReturn = Serialize("");\r
                        objReturn = Serialize("hello world!");\r
                        Assertion.AssertEquals("#string", "hello world!", objReturn);\r
+                       SoapMessage soapMsg = new SoapMessage();\r
+                       soapMsg.Headers = new Header[0];\r
+                       soapMsg.MethodName = "Equals";\r
+                       soapMsg.ParamNames = new String[0];\r
+                       soapMsg.ParamTypes = new Type[0];\r
+                       soapMsg.ParamValues = new object[0];\r
+                       soapMsg.XmlNameSpace = SoapServices.CodeXmlNamespaceForClrTypeNamespace("String", "System");\r
+                       _soapFormatterDeserializer.TopObject = new SoapMessage();\r
+                       objReturn = Serialize(soapMsg);\r
+                       _soapFormatterDeserializer.TopObject = null;\r
                        SimpleObject obj = new SimpleObject("simple object", 1);\r
                        objReturn = Serialize(obj);\r
                        Assertion.AssertEquals("#SimpleObject", obj, objReturn);\r
index fafa16dc495bcf319bf7993b4efd951d6a719e94..e2441ca513ea1a29deb6d6e208e7e818611ee434 100644 (file)
   </References>\r
   <DeploymentInformation target="" script="" strategy="File" />\r
   <Configuration runwithwarnings="True" name="Debug">\r
-    <CodeGeneration runtime="MsNet" compiler="Csc" warninglevel="4" includedebuginformation="True" optimize="True" unsafecodeallowed="True" generateoverflowchecks="True" mainclass="" target="Library" definesymbols="" generatexmldocumentation="False" win32Icon="" />\r
+    <CodeGeneration runtime="MsNet" compiler="Csc" warninglevel="0" includedebuginformation="True" optimize="True" unsafecodeallowed="True" generateoverflowchecks="True" mainclass="" target="Library" definesymbols="" generatexmldocumentation="False" win32Icon="" />\r
     <Execution commandlineparameters="" consolepause="True" />\r
     <Output directory="..\" assembly="Test" />\r
   </Configuration>\r
   <Configurations active="Debug">\r
     <Configuration runwithwarnings="True" name="Debug">\r
-      <CodeGeneration runtime="MsNet" compiler="Csc" warninglevel="4" includedebuginformation="True" optimize="True" unsafecodeallowed="True" generateoverflowchecks="True" mainclass="" target="Library" definesymbols="" generatexmldocumentation="False" win32Icon="" />\r
+      <CodeGeneration runtime="MsNet" compiler="Csc" warninglevel="0" includedebuginformation="True" optimize="True" unsafecodeallowed="True" generateoverflowchecks="True" mainclass="" target="Library" definesymbols="" generatexmldocumentation="False" win32Icon="" />\r
       <Execution commandlineparameters="" consolepause="True" />\r
       <Output directory="..\" assembly="Test" />\r
     </Configuration>\r