public IMethodCallMessage DeserializeRequest (Stream serializationStream, string uri) { if (serializationStream == null) { throw new ArgumentNullException ("serializationStream is null"); } Type svr_type = RemotingServices.GetServerTypeForUri (uri); if (svr_type == null) throw new RemotingException ("no registered server for uri " + uri); BinaryReader reader = new BinaryReader (serializationStream); string method_name = reader.ReadString (); int arg_count = reader.ReadInt32 (); object [] args = new object [arg_count]; for (int i = 0; i < arg_count; i++) { args [i] = DeserializeObject (reader); } MonoMethodMessage msg = new MonoMethodMessage (svr_type, method_name, args); msg.Uri = uri; return msg; }
static object[] ProcessResponse (IMethodReturnMessage mrm, MonoMethodMessage call) { // Check return type MethodInfo mi = (MethodInfo) call.MethodBase; if (mrm.ReturnValue != null && !mi.ReturnType.IsInstanceOfType (mrm.ReturnValue)) throw new InvalidCastException ("Return value has an invalid type"); // Check out parameters int no; if (call.NeedsOutProcessing (out no)) { ParameterInfo[] parameters = mi.GetParameters(); object[] outArgs = new object [no]; int narg = 0; foreach (ParameterInfo par in parameters) { if (par.IsOut && !par.ParameterType.IsByRef) { // Special marshalling required object outArg = par.Position < mrm.ArgCount ? mrm.GetArg (par.Position) : null; if (outArg != null) { object local = call.GetArg (par.Position); if (local == null) throw new RemotingException ("Unexpected null value in local out parameter '" + par.Name + "'"); RemotingServices.UpdateOutArgObject (par, local, outArg); } } else if (par.ParameterType.IsByRef) { object outArg = par.Position < mrm.ArgCount ? mrm.GetArg (par.Position) : null; if (outArg != null && !par.ParameterType.GetElementType ().IsInstanceOfType (outArg)) { throw new InvalidCastException ("Return argument '" + par.Name + "' has an invalid type"); } outArgs [narg++] = outArg; } } return outArgs; } else return new object [0]; }
internal object LoadRemoteFieldNew (IntPtr classPtr, IntPtr fieldPtr) { Mono.RuntimeClassHandle classHandle = new Mono.RuntimeClassHandle (classPtr); RuntimeFieldHandle fieldHandle = new RuntimeFieldHandle (fieldPtr); RuntimeTypeHandle typeHandle = classHandle.GetTypeHandle (); FieldInfo field = FieldInfo.GetFieldFromHandle (fieldHandle); if (InCurrentContext ()) { object o = _rp._server; return field.GetValue(o); } string typeName = Type.GetTypeFromHandle(typeHandle).FullName; string fieldName = field.Name; object[] inArgs = new object[] { typeName, fieldName }; object[] outArgsMsg = new object[1]; MethodInfo minfo = typeof(object).GetMethod("FieldGetter", BindingFlags.NonPublic | BindingFlags.Instance); if (minfo == null) throw new MissingMethodException ("System.Object", "FieldGetter"); MonoMethodMessage msg = new MonoMethodMessage (minfo, inArgs, outArgsMsg); object[] outArgs; Exception exc; RealProxy.PrivateInvoke (_rp, msg, out exc, out outArgs); if (exc != null) throw exc; return outArgs[0]; }