* ObjectReader.cs: Changed signature of ReadObjectGraph, so now it returns the
[mono.git] / mcs / class / corlib / System.Runtime.Serialization.Formatters.Binary / MessageFormatter.cs
index 5aa0b9997b48cf26cb7cd4401643c5fbc0d985a0..bfa81699a05df03bd327e78bd3939255d6ceb043 100644 (file)
@@ -48,7 +48,7 @@ namespace System.Runtime.Serialization.Formatters.Binary
                                infoArraySize++;\r
                        }\r
 \r
-                       if (call.InArgCount == 0)\r
+                       if (call.ArgCount == 0)\r
                                methodFlags |= MethodFlags.NoArguments;\r
                        else {\r
                                if (AllTypesArePrimitive (call.Args)) \r
@@ -161,7 +161,7 @@ namespace System.Runtime.Serialization.Formatters.Binary
                        else\r
                                contextFlag = MethodFlags.ExcludeLogicalCallContext;\r
 \r
-                       if (resp.Properties.Count > internalProperties.Length)\r
+                       if (resp.Properties.Count > internalProperties.Length && ((returnTypeTag & ReturnTypeTag.Exception) == 0))\r
                        {\r
                                extraProperties = GetExtraProperties (resp.Properties, internalProperties);\r
                                infoArrayLength++;\r
@@ -245,7 +245,7 @@ namespace System.Runtime.Serialization.Formatters.Binary
                                writer.Write ((byte) BinaryElement.End);\r
                }\r
 \r
-               public static object ReadMethodCall (BinaryReader reader, bool hasHeaders, HeaderHandler headerHandler, ISurrogateSelector surrogateSelector, StreamingContext context)\r
+               public static object ReadMethodCall (BinaryReader reader, bool hasHeaders, HeaderHandler headerHandler, ISurrogateSelector surrogateSelector, StreamingContext context, SerializationBinder binder)\r
                {\r
                        BinaryElement elem = (BinaryElement)reader.ReadByte();  // The element code\r
                        if (elem != BinaryElement.MethodCall) throw new SerializationException("Invalid format. Expected BinaryElement.MethodCall, found " +  elem);\r
@@ -269,6 +269,7 @@ namespace System.Runtime.Serialization.Formatters.Binary
                        object methodSignature = null;
                        object callContext = null;
                        object[] extraProperties = null;
+                       Header[] headers = null;
 
                        if ((flags & MethodFlags.PrimitiveArguments) > 0)
                        {
@@ -283,8 +284,11 @@ namespace System.Runtime.Serialization.Formatters.Binary
 
                        if ((flags & MethodFlags.NeedsInfoArrayMask) > 0)\r
                        {\r
-                               ObjectReader objectReader = new ObjectReader(surrogateSelector, context);\r
-                               object[] msgInfo = (object[]) objectReader.ReadObjectGraph (reader, hasHeaders, headerHandler);\r
+                               ObjectReader objectReader = new ObjectReader(surrogateSelector, context, binder);\r
+\r
+                               object result;\r
+                               objectReader.ReadObjectGraph (reader, hasHeaders, out result, out headers);\r
+                               object[] msgInfo = (object[]) result;\r
 \r
                                if ((flags & MethodFlags.ArgumentsInSimpleArray) > 0) {\r
                                        arguments = msgInfo;\r
@@ -313,12 +317,17 @@ namespace System.Runtime.Serialization.Formatters.Binary
 \r
                        if (arguments == null) arguments = new object[0];\r
 \r
-                       Header[] methodInfo = new Header[5];\r
+                       string uri = null;\r
+                       if (headerHandler != null)\r
+                               uri = headerHandler(headers) as string;\r
+\r
+                       Header[] methodInfo = new Header[6];\r
                        methodInfo[0] = new Header("__MethodName", methodName);
                        methodInfo[1] = new Header("__MethodSignature", methodSignature);
                        methodInfo[2] = new Header("__TypeName", className);
                        methodInfo[3] = new Header("__Args", arguments);
                        methodInfo[4] = new Header("__CallContext", callContext);
+                       methodInfo[5] = new Header("__Uri", uri);
 
                        MethodCall call = new MethodCall (methodInfo);
 
@@ -330,7 +339,7 @@ namespace System.Runtime.Serialization.Formatters.Binary
                        return call;
                }\r
 \r
-               public static object ReadMethodResponse (BinaryReader reader, bool hasHeaders, HeaderHandler headerHandler, IMethodCallMessage methodCallMessage, ISurrogateSelector surrogateSelector, StreamingContext context)\r
+               public static object ReadMethodResponse (BinaryReader reader, bool hasHeaders, HeaderHandler headerHandler, IMethodCallMessage methodCallMessage, ISurrogateSelector surrogateSelector, StreamingContext context, SerializationBinder binder)\r
                {\r
                        BinaryElement elem = (BinaryElement)reader.ReadByte();  // The element code\r
                        if (elem != BinaryElement.MethodResponse) throw new SerializationException("Invalid format. Expected BinaryElement.MethodResponse, found " +  elem);\r
@@ -348,6 +357,7 @@ namespace System.Runtime.Serialization.Formatters.Binary
                        LogicalCallContext callContext = null;\r
                        Exception exception = null;\r
                        object[] extraProperties = null;
+                       Header[] headers = null;
 \r
                        if ((typeTag & ReturnTypeTag.PrimitiveType) > 0)
                        {\r
@@ -372,13 +382,15 @@ namespace System.Runtime.Serialization.Formatters.Binary
                        {\r
                                // There objects that need to be deserialized using an ObjectReader\r
 \r
-                               ObjectReader objectReader = new ObjectReader(surrogateSelector, context);\r
-                               object[] msgInfo = (object[]) objectReader.ReadObjectGraph (reader, hasHeaders, headerHandler);\r
+                               ObjectReader objectReader = new ObjectReader(surrogateSelector, context, binder);\r
+                               object result;\r
+                               objectReader.ReadObjectGraph (reader, hasHeaders, out result, out headers);\r
+                               object[] msgInfo = (object[]) result;\r
 \r
                                if ((typeTag & ReturnTypeTag.Exception) > 0) {\r
                                        exception = (Exception) msgInfo[0];\r
                                }\r
-                               if ((flags & MethodFlags.NoArguments) > 0 || (flags & MethodFlags.PrimitiveArguments) > 0) {\r
+                               else if ((flags & MethodFlags.NoArguments) > 0 || (flags & MethodFlags.PrimitiveArguments) > 0) {\r
                                        int n = 0;\r
                                        if ((typeTag & ReturnTypeTag.ObjectType) > 0) returnValue = msgInfo [n++];\r
                                        if (hasContextInfo) callContext = (LogicalCallContext)msgInfo[n++];\r
@@ -399,6 +411,9 @@ namespace System.Runtime.Serialization.Formatters.Binary
                                reader.ReadByte ();     // Reads the stream ender\r
                        }\r
 \r
+                       if (headerHandler != null) \r
+                               headerHandler(headers);\r
+\r
                        if (exception != null)\r
                                return new ReturnMessage (exception, methodCallMessage);\r
                        else\r