//
using System;
+using System.Reflection;
using System.Runtime.Remoting;
using System.Runtime.Remoting.Messaging;
using System.Runtime.Remoting.Activation;
IMethodReturnMessage res_msg = (IMethodReturnMessage)rp.Invoke (msg);
- if (res_msg.LogicalCallContext != null)
- CallContext.SetCurrentCallContext (res_msg.LogicalCallContext);
+ if (!(res_msg is IConstructionReturnMessage) && (res_msg.Exception == null))
+ out_args = ProcessResponse (res_msg, mMsg);
+ else
+ out_args = res_msg.OutArgs;
+
+ if (res_msg.LogicalCallContext != null && res_msg.LogicalCallContext.HasInfo)
+ CallContext.UpdateCurrentCallContext (res_msg.LogicalCallContext);
exc = res_msg.Exception;
- out_args = res_msg.OutArgs;
// todo: remove throw exception from the runtime invoke
if (null != exc)
{
return _server;
}
+
+ static object[] ProcessResponse (IMethodReturnMessage mrm, IMethodCallMessage call)
+ {
+ // Check return type
+
+ MethodInfo mi = (MethodInfo) mrm.MethodBase;
+ if (mrm.ReturnValue != null && !mi.ReturnType.IsInstanceOfType (mrm.ReturnValue))
+ throw new RemotingException ("Return value has an invalid type");
+
+ // Check out parameters
+
+ if (mrm.OutArgCount > 0)
+ {
+ ParameterInfo[] parameters = mi.GetParameters();
+ int no = 0;
+ foreach (ParameterInfo par in parameters)
+ if (par.ParameterType.IsByRef) no++;
+
+ object[] outArgs = new object [no];
+ int narg = 0;
+ int nout = 0;
+
+ foreach (ParameterInfo par in parameters)
+ {
+ if (par.IsOut && !par.ParameterType.IsByRef)
+ {
+ // Special marshalling required
+
+ object outArg = mrm.GetOutArg (nout++);
+ if (outArg != null) {
+ object local = call.GetArg (par.Position);
+ if (local == null) throw new RemotingException ("Unexpected null value in local out parameter");
+ RemotingServices.UpdateOutArgObject (par, local, outArg);
+ }
+ }
+ else if (par.ParameterType.IsByRef)
+ {
+ object outArg = mrm.GetOutArg (nout++);
+ if (outArg != null && !par.ParameterType.IsInstanceOfType (outArg))
+ throw new RemotingException ("Return argument '" + par.Name + "' has an invalid type");
+ outArgs [narg++] = outArg;
+ }
+ }
+ return outArgs;
+ }
+ else
+ return new object [0];
+ }
}
}
_objectIdentity.NotifyClientDynamicSinks (false, request, true, false);
- if (!(response is IConstructionReturnMessage))
- CheckResponse (response, request);
-
return response;
}
_ctorCall.CopyFrom (request);
return ActivationServices.Activate (this, _ctorCall);
}
-
- void CheckResponse (IMessage response, IMessage call)
- {
- IMethodReturnMessage mrm = (IMethodReturnMessage) response;
- if (mrm.Exception != null) return;
-
- // Check return type
-
- MethodInfo mi = (MethodInfo) mrm.MethodBase;
- if (mrm.ReturnValue != null && !mi.ReturnType.IsInstanceOfType (mrm.ReturnValue))
- throw new RemotingException ("Return value has an invalid type");
-
- // Check out parameters
-
- ParameterInfo[] parameters = mi.GetParameters();
- int narg = 0;
-
- foreach (ParameterInfo pi in parameters)
- if(pi.ParameterType.IsByRef) {
- object pval = mrm.GetOutArg (narg++);
- if (pval != null && !pi.ParameterType.IsInstanceOfType (pval))
- throw new RemotingException ("Return argument has an invalid type");
- }
- }
}
}