private void UpdateNames() { RemotingMethodCachedData reflectionCachedData = InternalRemotingServices.GetReflectionCachedData(this.GetMethodBase()); this._typeName = reflectionCachedData.TypeAndAssemblyName; this._MethodName = reflectionCachedData.MethodName; }
internal MethodResponse(IMethodCallMessage msg, object handlerObject, BinaryMethodReturnMessage smuggledMrm) { if (msg != null) { this.MI = msg.MethodBase; this._methodCache = InternalRemotingServices.GetReflectionCachedData(this.MI); this.methodName = msg.MethodName; this.uri = msg.Uri; this.typeName = msg.TypeName; if (this._methodCache.IsOverloaded()) { this.methodSignature = (Type[])msg.MethodSignature; } this.argCount = this._methodCache.Parameters.Length; } this.retVal = smuggledMrm.ReturnValue; this.outArgs = smuggledMrm.Args; this.fault = smuggledMrm.Exception; this.callContext = smuggledMrm.LogicalCallContext; if (smuggledMrm.HasProperties) { smuggledMrm.PopulateMessageProperties(this.Properties); } this.fSoap = false; }
internal static void PropagateOutParameters(IMessage msg, object[] outArgs, object returnValue) { Message message = msg as Message; if (message == null) { ConstructorCallMessage message2 = msg as ConstructorCallMessage; if (message2 != null) { message = message2.GetMessage(); } } if (message == null) { throw new ArgumentException(Environment.GetResourceString("Remoting_Proxy_ExpectedOriginalMessage")); } RemotingMethodCachedData reflectionCachedData = InternalRemotingServices.GetReflectionCachedData(message.GetMethodBase()); if ((outArgs != null) && (outArgs.Length > 0)) { object[] args = message.Args; ParameterInfo[] parameters = reflectionCachedData.Parameters; foreach (int num in reflectionCachedData.MarshalRequestArgMap) { ParameterInfo info = parameters[num]; if ((info.IsIn && info.ParameterType.IsByRef) && !info.IsOut) { outArgs[num] = args[num]; } } if (reflectionCachedData.NonRefOutArgMap.Length > 0) { foreach (int num2 in reflectionCachedData.NonRefOutArgMap) { Array destinationArray = args[num2] as Array; if (destinationArray != null) { Array.Copy((Array)outArgs[num2], destinationArray, destinationArray.Length); } } } int[] outRefArgMap = reflectionCachedData.OutRefArgMap; if (outRefArgMap.Length > 0) { foreach (int num3 in outRefArgMap) { ValidateReturnArg(outArgs[num3], parameters[num3].ParameterType); } } } if ((message.GetCallType() & 15) != 1) { Type returnType = reflectionCachedData.ReturnType; if (returnType != null) { ValidateReturnArg(returnValue, returnType); } } message.PropagateOutParameters(outArgs, returnValue); }
internal static RemotingMethodCachedData GetReflectionCachedData(MethodBase mi) { RemotingMethodCachedData data = null; RuntimeMethodInfo ri = null; RuntimeConstructorInfo info2 = null; ri = mi as RuntimeMethodInfo; if (ri != null) { data = (RemotingMethodCachedData)ri.RemotingCache[CacheObjType.RemotingData]; if (data == null) { ri.RemotingCache[CacheObjType.RemotingData] = data = new RemotingMethodCachedData(ri); } return(data); } info2 = mi as RuntimeConstructorInfo; if (info2 == null) { throw new ArgumentException(Environment.GetResourceString("Argument_MustBeRuntimeReflectionObject")); } data = (RemotingMethodCachedData)info2.RemotingCache[CacheObjType.RemotingData]; if (data == null) { info2.RemotingCache[CacheObjType.RemotingData] = data = new RemotingMethodCachedData(info2); } return(data); }
public string GetArgName(int index) { this.ResolveMethod(); RemotingMethodCachedData reflectionCachedData = InternalRemotingServices.GetReflectionCachedData(this.MI); return(reflectionCachedData.Parameters[index].Name); }
public MethodResponse(Header[] h1, IMethodCallMessage mcm) { if (mcm == null) { throw new ArgumentNullException("mcm"); } Message message = mcm as Message; if (message != null) { this.MI = message.GetMethodBase(); } else { this.MI = mcm.MethodBase; } if (this.MI == null) { throw new RemotingException(string.Format(CultureInfo.CurrentCulture, Environment.GetResourceString("Remoting_Message_MethodMissing"), new object[] { mcm.MethodName, mcm.TypeName })); } this._methodCache = InternalRemotingServices.GetReflectionCachedData(this.MI); this.argCount = this._methodCache.Parameters.Length; this.fSoap = true; this.FillHeaders(h1); }
internal static object[] CoerceArgs(IMethodMessage m) { MethodBase methodBase = m.MethodBase; RemotingMethodCachedData reflectionCachedData = InternalRemotingServices.GetReflectionCachedData(methodBase); return(Message.CoerceArgs(m, reflectionCachedData.Parameters)); }
public void ServerCallback(IAsyncResult ar) { if (!(this._asyncEnd != (MethodInfo)null)) { return; } RemotingMethodCachedData reflectionCachedData1 = InternalRemotingServices.GetReflectionCachedData((MethodBase)this._asyncEnd); RemotingMethodCachedData reflectionCachedData2 = InternalRemotingServices.GetReflectionCachedData(this._msg.MethodBase); ParameterInfo[] parameters = reflectionCachedData1.Parameters; object[] objArray = new object[parameters.Length]; objArray[parameters.Length - 1] = (object)ar; object[] args = this._msg.Args; AsyncMessageHelper.GetOutArgs(reflectionCachedData2.Parameters, args, objArray); StackBuilderSink stackBuilderSink = new StackBuilderSink(this._serverObject); object[] outArgs1; object ret = stackBuilderSink.PrivateProcessMessage(this._asyncEnd.MethodHandle, Message.CoerceArgs((MethodBase)this._asyncEnd, objArray, parameters), this._serverObject, out outArgs1); if (outArgs1 != null) { outArgs1 = ArgMapper.ExpandAsyncEndArgsToSyncArgs(reflectionCachedData2, outArgs1); } stackBuilderSink.CopyNonByrefOutArgsFromOriginalArgs(reflectionCachedData2, args, ref outArgs1); object[] outArgs2 = outArgs1; int argCount = this._msg.ArgCount; LogicalCallContext logicalCallContext = Thread.CurrentThread.GetMutableExecutionContext().LogicalCallContext; IMethodCallMessage mcm = this._msg; this.AsyncProcessResponse((IMessage) new ReturnMessage(ret, outArgs2, argCount, logicalCallContext, mcm), (ITransportHeaders)null, (Stream)null); }
internal void SetObjectFromSoapData(SerializationInfo info) { this.methodName = info.GetString("__methodName"); ArrayList arrayList = (ArrayList)info.GetValue("__paramNameList", typeof(ArrayList)); Hashtable keyToNamespaceTable = (Hashtable)info.GetValue("__keyToNamespaceTable", typeof(Hashtable)); if (this.MI == null) { ArrayList argValues = new ArrayList(); ArrayList argNames = arrayList; for (int index = 0; index < argNames.Count; ++index) { argValues.Add(info.GetValue((string)argNames[index], typeof(object))); } if (!(this.ResolveType() is RuntimeType t2)) { throw new RemotingException(string.Format((IFormatProvider)CultureInfo.CurrentCulture, Environment.GetResourceString("Remoting_BadType"), (object)this.typeName)); } this.ResolveOverloadedMethod(t2, this.methodName, argNames, argValues); if (this.MI == null) { throw new RemotingException(string.Format((IFormatProvider)CultureInfo.CurrentCulture, Environment.GetResourceString("Remoting_Message_MethodMissing"), (object)this.methodName, (object)this.typeName)); } } RemotingMethodCachedData reflectionCachedData = InternalRemotingServices.GetReflectionCachedData(this.MI); ParameterInfo[] parameters = reflectionCachedData.Parameters; int[] marshalRequestArgMap = reflectionCachedData.MarshalRequestArgMap; int[] outOnlyArgMap = reflectionCachedData.OutOnlyArgMap; object obj = this.InternalProperties == null ? (object)null : this.InternalProperties[(object)"__UnorderedParams"]; this.args = new object[parameters.Length]; if (obj != null && obj is bool flag && flag) { for (int index1 = 0; index1 < arrayList.Count; ++index1) { string name = (string)arrayList[index1]; int index2 = -1; for (int index3 = 0; index3 < parameters.Length; ++index3) { if (name.Equals(parameters[index3].Name)) { index2 = parameters[index3].Position; break; } } if (index2 == -1) { index2 = name.StartsWith("__param", StringComparison.Ordinal) ? int.Parse(name.Substring(7), (IFormatProvider)CultureInfo.InvariantCulture) : throw new RemotingException(Environment.GetResourceString("Remoting_Message_BadSerialization")); } if (index2 >= this.args.Length) { throw new RemotingException(Environment.GetResourceString("Remoting_Message_BadSerialization")); } this.args[index2] = Message.SoapCoerceArg(info.GetValue(name, typeof(object)), parameters[index2].ParameterType, keyToNamespaceTable); } }
internal static object[] ExpandAsyncEndArgsToSyncArgs(RemotingMethodCachedData syncMethod, object[] asyncEndArgs) { object[] objArray = new object[syncMethod.Parameters.Length]; int[] outRefArgMap = syncMethod.OutRefArgMap; for (int i = 0; i < outRefArgMap.Length; i++) { objArray[outRefArgMap[i]] = asyncEndArgs[i]; } return(objArray); }
internal ArgMapper(MethodBase mb, bool fOut) { this._methodCachedData = InternalRemotingServices.GetReflectionCachedData(mb); if (fOut) { this._map = this._methodCachedData.MarshalResponseArgMap; } else { this._map = this._methodCachedData.MarshalRequestArgMap; } }
private void PopulateOutArguments(RemotingMethodCachedData methodCache) { ParameterInfo[] parameters = methodCache.Parameters; foreach (int num in methodCache.OutOnlyArgMap) { Type elementType = parameters[num].ParameterType.GetElementType(); if (elementType.IsValueType) { this.args[num] = Activator.CreateInstance(elementType, true); } } }
internal static Type[] GenerateMethodSignature(MethodBase mb) { RemotingMethodCachedData reflectionCachedData = InternalRemotingServices.GetReflectionCachedData(mb); ParameterInfo[] parameters = reflectionCachedData.Parameters; Type[] array = new Type[parameters.Length]; for (int i = 0; i < parameters.Length; i++) { array[i] = parameters[i].ParameterType; } return(array); }
internal ArgMapper(IMethodMessage mm, bool fOut) { this._mm = mm; this._methodCachedData = InternalRemotingServices.GetReflectionCachedData(this._mm.MethodBase); if (fOut) { this._map = this._methodCachedData.MarshalResponseArgMap; } else { this._map = this._methodCachedData.MarshalRequestArgMap; } }
public string GetArgName(int index) { if (this.MI == null) { return("__param" + index); } RemotingMethodCachedData reflectionCachedData = InternalRemotingServices.GetReflectionCachedData(this.MI); ParameterInfo[] parameters = reflectionCachedData.Parameters; if ((index < 0) || (index >= parameters.Length)) { throw new ArgumentOutOfRangeException("index"); } return(reflectionCachedData.Parameters[index].Name); }
public string GetArgName(int index) { if (index >= this.ArgCount) { throw new ArgumentOutOfRangeException("index"); } RemotingMethodCachedData reflectionCachedData = InternalRemotingServices.GetReflectionCachedData(this.GetMethodBase()); ParameterInfo[] parameters = reflectionCachedData.Parameters; if (index < parameters.Length) { return(parameters[index].Name); } return("VarArg" + (index - parameters.Length)); }
internal void CopyNonByrefOutArgsFromOriginalArgs(RemotingMethodCachedData methodCache, object[] args, ref object[] marshalResponseArgs) { int[] nonRefOutArgMap = methodCache.NonRefOutArgMap; if (nonRefOutArgMap.Length > 0) { if (marshalResponseArgs == null) { marshalResponseArgs = new object[methodCache.Parameters.Length]; } foreach (int num in nonRefOutArgMap) { marshalResponseArgs[num] = args[num]; } } }
/// <include file='doc\ChannelSinkStacks.uex' path='docs/doc[@for="ServerChannelSinkStack.ServerCallback"]/*' /> public void ServerCallback(IAsyncResult ar) { if (_asyncEnd != null) { RemotingMethodCachedData asyncEndCache = (RemotingMethodCachedData) InternalRemotingServices.GetReflectionCachedData(_asyncEnd); MethodInfo syncMI = (MethodInfo)_msg.MethodBase; RemotingMethodCachedData syncCache = (RemotingMethodCachedData) InternalRemotingServices.GetReflectionCachedData(syncMI); ParameterInfo[] paramList = asyncEndCache.Parameters; // construct list to pass into End Object[] parameters = new Object[paramList.Length]; parameters[paramList.Length - 1] = ar; // last parameter is the async result Object[] syncMsgArgs = _msg.Args; // copy out and ref parameters to the parameters list AsyncMessageHelper.GetOutArgs(syncCache.Parameters, syncMsgArgs, parameters); Object[] outArgs; StackBuilderSink s = new StackBuilderSink(_serverObject); Object returnValue = s.PrivateProcessMessage(_asyncEnd, System.Runtime.Remoting.Messaging.Message.CoerceArgs(_asyncEnd, parameters, paramList), _serverObject, 0, false, out outArgs); // The outArgs list is associated with the EndXXX method. We need to make sure // it is sized properly for the out args of the XXX method. if (outArgs != null) { outArgs = ArgMapper.ExpandAsyncEndArgsToSyncArgs(syncCache, outArgs); } s.CopyNonByrefOutArgsFromOriginalArgs(syncCache, syncMsgArgs, ref outArgs); IMessage retMessage = new ReturnMessage( returnValue, outArgs, _msg.ArgCount, CallContext.GetLogicalCallContext(), _msg); AsyncProcessResponse(retMessage, null, null); } } // ServerCallback
public virtual IConstructionReturnMessage Activate(IConstructionCallMessage ctorMsg) { if (ctorMsg == null) { throw new ArgumentNullException("ctorMsg"); } if (ctorMsg.Properties.Contains((object)"Remote")) { return(LocalActivator.DoRemoteActivation(ctorMsg)); } if (!ctorMsg.Properties.Contains((object)"Permission")) { return(ctorMsg.Activator.Activate(ctorMsg)); } Type activationType = ctorMsg.ActivationType; object[] activationAttributes = (object[])null; if (activationType.IsContextful) { IList contextProperties = ctorMsg.ContextProperties; if (contextProperties != null && contextProperties.Count > 0) { activationAttributes = new object[1] { (object)new RemotePropertyHolderAttribute(contextProperties) } } ; } RemotingMethodCachedData reflectionCachedData = InternalRemotingServices.GetReflectionCachedData(LocalActivator.GetMethodBase(ctorMsg)); object[] args = Message.CoerceArgs((IMethodMessage)ctorMsg, reflectionCachedData.Parameters); object serverObj = Activator.CreateInstance(activationType, args, activationAttributes); if (RemotingServices.IsClientProxy(serverObj)) { RedirectionProxy redirectionProxy = new RedirectionProxy((MarshalByRefObject)serverObj, activationType); // ISSUE: variable of the null type __Null local = null; Type RequestedType = activationType; RemotingServices.MarshalInternal((MarshalByRefObject)redirectionProxy, (string)local, RequestedType); serverObj = (object)redirectionProxy; } return(ActivationServices.SetupConstructionReply(serverObj, ctorMsg, (Exception)null)); }
public string GetArgName(int index) { if (this._outArgs == null) { if (index < 0 || index >= this._outArgsCount) { throw new ArgumentOutOfRangeException("index"); } } else if (index < 0 || index >= this._outArgs.Length) { throw new ArgumentOutOfRangeException("index"); } if (this._methodBase != null) { RemotingMethodCachedData reflectionCachedData = InternalRemotingServices.GetReflectionCachedData(this._methodBase); return(reflectionCachedData.Parameters[index].Name); } return("__param" + index); }
public virtual IConstructionReturnMessage Activate(IConstructionCallMessage ctorMsg) { if (ctorMsg == null) { throw new ArgumentNullException("ctorMsg"); } if (ctorMsg.Properties.Contains("Remote")) { return(LocalActivator.DoRemoteActivation(ctorMsg)); } if (ctorMsg.Properties.Contains("Permission")) { Type activationType = ctorMsg.ActivationType; object[] activationAttributes = null; if (activationType.IsContextful) { IList contextProperties = ctorMsg.ContextProperties; if (contextProperties != null && contextProperties.Count > 0) { RemotePropertyHolderAttribute remotePropertyHolderAttribute = new RemotePropertyHolderAttribute(contextProperties); activationAttributes = new object[] { remotePropertyHolderAttribute }; } } MethodBase methodBase = LocalActivator.GetMethodBase(ctorMsg); RemotingMethodCachedData reflectionCachedData = InternalRemotingServices.GetReflectionCachedData(methodBase); object[] args = Message.CoerceArgs(ctorMsg, reflectionCachedData.Parameters); object obj = Activator.CreateInstance(activationType, args, activationAttributes); if (RemotingServices.IsClientProxy(obj)) { RedirectionProxy redirectionProxy = new RedirectionProxy((MarshalByRefObject)obj, activationType); RemotingServices.MarshalInternal(redirectionProxy, null, activationType); obj = redirectionProxy; } return(ActivationServices.SetupConstructionReply(obj, ctorMsg, null)); } return(ctorMsg.Activator.Activate(ctorMsg)); }
internal MethodResponse(IMethodCallMessage msg, SmuggledMethodReturnMessage smuggledMrm, ArrayList deserializedArgs) { this.MI = msg.MethodBase; this._methodCache = InternalRemotingServices.GetReflectionCachedData(this.MI); this.methodName = msg.MethodName; this.uri = msg.Uri; this.typeName = msg.TypeName; if (this._methodCache.IsOverloaded()) { this.methodSignature = (Type[])msg.MethodSignature; } this.retVal = smuggledMrm.GetReturnValue(deserializedArgs); this.outArgs = smuggledMrm.GetArgs(deserializedArgs); this.fault = smuggledMrm.GetException(deserializedArgs); this.callContext = smuggledMrm.GetCallContext(deserializedArgs); if (smuggledMrm.MessagePropertyCount > 0) { smuggledMrm.PopulateMessageProperties(this.Properties, deserializedArgs); } this.argCount = this._methodCache.Parameters.Length; this.fSoap = false; }
public void ServerCallback(IAsyncResult ar) { if (this._asyncEnd != null) { object[] objArray3; RemotingMethodCachedData reflectionCachedData = InternalRemotingServices.GetReflectionCachedData((MethodBase)this._asyncEnd); MethodInfo methodBase = (MethodInfo)this._msg.MethodBase; RemotingMethodCachedData syncMethod = InternalRemotingServices.GetReflectionCachedData((MethodBase)methodBase); ParameterInfo[] parameters = reflectionCachedData.Parameters; object[] endArgs = new object[parameters.Length]; endArgs[parameters.Length - 1] = ar; object[] args = this._msg.Args; AsyncMessageHelper.GetOutArgs(syncMethod.Parameters, args, endArgs); StackBuilderSink sink = new StackBuilderSink(this._serverObject); object ret = sink.PrivateProcessMessage(this._asyncEnd.MethodHandle, Message.CoerceArgs(this._asyncEnd, endArgs, parameters), this._serverObject, 0, false, out objArray3); if (objArray3 != null) { objArray3 = ArgMapper.ExpandAsyncEndArgsToSyncArgs(syncMethod, objArray3); } sink.CopyNonByrefOutArgsFromOriginalArgs(syncMethod, args, ref objArray3); IMessage msg = new ReturnMessage(ret, objArray3, this._msg.ArgCount, CallContext.GetLogicalCallContext(), this._msg); this.AsyncProcessResponse(msg, null, null); } }
public void ServerCallback(IAsyncResult ar) { if (this._asyncEnd != null) { RemotingMethodCachedData reflectionCachedData = InternalRemotingServices.GetReflectionCachedData(this._asyncEnd); MethodInfo mi = (MethodInfo)this._msg.MethodBase; RemotingMethodCachedData reflectionCachedData2 = InternalRemotingServices.GetReflectionCachedData(mi); ParameterInfo[] parameters = reflectionCachedData.Parameters; object[] array = new object[parameters.Length]; array[parameters.Length - 1] = ar; object[] args = this._msg.Args; AsyncMessageHelper.GetOutArgs(reflectionCachedData2.Parameters, args, array); StackBuilderSink stackBuilderSink = new StackBuilderSink(this._serverObject); object[] array2; object ret = stackBuilderSink.PrivateProcessMessage(this._asyncEnd.MethodHandle, Message.CoerceArgs(this._asyncEnd, array, parameters), this._serverObject, out array2); if (array2 != null) { array2 = ArgMapper.ExpandAsyncEndArgsToSyncArgs(reflectionCachedData2, array2); } stackBuilderSink.CopyNonByrefOutArgsFromOriginalArgs(reflectionCachedData2, args, ref array2); IMessage msg = new ReturnMessage(ret, array2, this._msg.ArgCount, Thread.CurrentThread.GetMutableExecutionContext().LogicalCallContext, this._msg); this.AsyncProcessResponse(msg, null, null); } }
void PopulateOutArguments(RemotingMethodCachedData methodCache) { ParameterInfo[] parameterInfos = methodCache.Parameters; // We need to have a dummy object in the array for out parameters // that have value types. foreach (int outArg in methodCache.OutOnlyArgMap) { Type type = parameterInfos[outArg].ParameterType.GetElementType(); if (type.IsValueType) args[outArg] = Activator.CreateInstance(type, true); } }
[System.Security.SecurityCritical] // auto-generated public MethodResponse(Header[] h1, IMethodCallMessage mcm) { if (mcm == null) throw new ArgumentNullException("mcm"); Contract.EndContractBlock(); Message msg = mcm as Message; if (null != msg) { MI = (MethodBase)msg.GetMethodBase(); } else { MI = (MethodBase)mcm.MethodBase; } if (MI == null) { throw new RemotingException( String.Format( CultureInfo.CurrentCulture, Environment.GetResourceString( "Remoting_Message_MethodMissing"), mcm.MethodName, mcm.TypeName)); } _methodCache = InternalRemotingServices.GetReflectionCachedData(MI); argCount = _methodCache.Parameters.Length; fSoap = true; FillHeaders(h1); }
[System.Security.SecurityCritical] // auto-generated internal MethodResponse(IMethodCallMessage msg, SmuggledMethodReturnMessage smuggledMrm, ArrayList deserializedArgs) { MI = (MethodBase)msg.MethodBase; _methodCache = InternalRemotingServices.GetReflectionCachedData(MI); methodName = msg.MethodName; uri = msg.Uri; typeName = msg.TypeName; if (_methodCache.IsOverloaded()) methodSignature = (Type[])msg.MethodSignature; retVal = smuggledMrm.GetReturnValue(deserializedArgs); outArgs = smuggledMrm.GetArgs(deserializedArgs); fault = smuggledMrm.GetException(deserializedArgs); callContext = smuggledMrm.GetCallContext(deserializedArgs); if (smuggledMrm.MessagePropertyCount > 0) smuggledMrm.PopulateMessageProperties(Properties, deserializedArgs); argCount = _methodCache.Parameters.Length; fSoap = false; }
[System.Security.SecurityCritical] // auto-generated internal MethodResponse(IMethodCallMessage msg, Object handlerObject, BinaryMethodReturnMessage smuggledMrm) { if (msg != null) { MI = (MethodBase)msg.MethodBase; _methodCache = InternalRemotingServices.GetReflectionCachedData(MI); methodName = msg.MethodName; uri = msg.Uri; typeName = msg.TypeName; if (_methodCache.IsOverloaded()) methodSignature = (Type[])msg.MethodSignature; argCount = _methodCache.Parameters.Length; } retVal = smuggledMrm.ReturnValue; outArgs = smuggledMrm.Args; fault = smuggledMrm.Exception; callContext = smuggledMrm.LogicalCallContext; if (smuggledMrm.HasProperties) smuggledMrm.PopulateMessageProperties(Properties); fSoap = false; }
internal virtual IMessage SyncProcessMessage(IMessage msg, int methodPtr, bool fExecuteInContext) { // Validate message here IMessage errMsg = InternalSink.ValidateMessage(msg); if (errMsg != null) { return(errMsg); } IMethodCallMessage mcMsg = msg as IMethodCallMessage; IMessage retMessage; LogicalCallContext oldCallCtx = null; try { Object server = _server; BCLDebug.Assert((server != null) == (!_bStatic), "Invalid state in stackbuilder sink?"); // validate the method base if necessary VerifyIsOkToCallMethod(server, mcMsg); // install call context onto the thread, holding onto // the one that is currently on the thread LogicalCallContext messageCallContext = null; if (mcMsg != null) { messageCallContext = mcMsg.LogicalCallContext; } else { messageCallContext = (LogicalCallContext)msg.Properties["__CallContext"]; } oldCallCtx = CallContext.SetLogicalCallContext(messageCallContext); messageCallContext.PropagateIncomingHeadersToCallContext(msg); PreserveThreadPrincipalIfNecessary(messageCallContext, oldCallCtx); // NOTE: target for dispatch will be NULL when the StackBuilderSink // is used for async delegates on static methods. RemotingServices.LogRemotingStage(RemotingServices.SERVER_MSG_STACK_BUILD); // *** NOTE *** // Although we always pass _server to these calls in the EE, // when we execute using Message::Dispatch we are using TP as // the this-ptr ... (what the call site thinks is the this-ptr) // when we execute using StackBuilderSink::PrivatePM we use // _server as the this-ptr (which could be different if there // is interception for strictly MBR types in the same AD). // ************ if (IsOKToStackBlt(mcMsg, server) && ((Message)mcMsg).Dispatch(server, fExecuteInContext)) { //retMessage = StackBasedReturnMessage.GetObjectFromPool((Message)mcMsg); retMessage = new StackBasedReturnMessage(); ((StackBasedReturnMessage)retMessage).InitFields((Message)mcMsg); // call context could be different then the one from before the call. LogicalCallContext latestCallContext = CallContext.GetLogicalCallContext(); // retrieve outgoing response headers latestCallContext.PropagateOutgoingHeadersToMessage(retMessage); // Install call context back into Message (from the thread) ((StackBasedReturnMessage)retMessage).SetLogicalCallContext(latestCallContext); } else { MethodBase mb = GetMethodBase(mcMsg); Object[] outArgs = null; Object ret = null; RemotingMethodCachedData methodCache = InternalRemotingServices.GetReflectionCachedData(mb); Message.DebugOut("StackBuilderSink::Calling PrivateProcessMessage\n"); Object[] args = Message.CoerceArgs(mcMsg, methodCache.Parameters); ret = PrivateProcessMessage( mb, args, server, methodPtr, fExecuteInContext, out outArgs); CopyNonByrefOutArgsFromOriginalArgs(methodCache, args, ref outArgs); // call context could be different then the one from before the call. LogicalCallContext latestCallContext = CallContext.GetLogicalCallContext(); retMessage = new ReturnMessage( ret, outArgs, (outArgs == null ? 0 : outArgs.Length), latestCallContext, mcMsg); // retrieve outgoing response headers latestCallContext.PropagateOutgoingHeadersToMessage(retMessage); } // restore the call context on the thread CallContext.SetLogicalCallContext(oldCallCtx); } catch (Exception e) { Message.DebugOut( "StackBuilderSink::The server object probably threw an exception " + e.Message + e.StackTrace + "\n"); retMessage = new ReturnMessage(e, mcMsg); ((ReturnMessage)retMessage).SetLogicalCallContext(mcMsg.LogicalCallContext); if (oldCallCtx != null) { CallContext.SetLogicalCallContext(oldCallCtx); } } RemotingServices.LogRemotingStage(RemotingServices.SERVER_RET_SINK_CHAIN); return(retMessage); }
[System.Security.SecurityCritical] // auto-generated internal ArgMapper(IMethodMessage mm, bool fOut) { _mm = mm; MethodBase mb = (MethodBase)_mm.MethodBase; _methodCachedData = InternalRemotingServices.GetReflectionCachedData(mb); if (fOut) _map = _methodCachedData.MarshalResponseArgMap; else _map = _methodCachedData.MarshalRequestArgMap; } // ArgMapper
[System.Security.SecurityCritical] // auto-generated internal ArgMapper(MethodBase mb, bool fOut) { _methodCachedData = InternalRemotingServices.GetReflectionCachedData(mb); if (fOut) _map = _methodCachedData.MarshalResponseArgMap; else _map = _methodCachedData.MarshalRequestArgMap; } // ArgMapper
} // GetParameterMaps // // Helper methods for expanding and contracting argument lists // when translating from async methods to [....] methods and back. // internal static Object[] ExpandAsyncEndArgsToSyncArgs(RemotingMethodCachedData syncMethod, Object[] asyncEndArgs) { // This is when we have a list of args associated with EndFoo(), and // we want to size it to a list of args associated with Foo(); Object[] args = new Object[syncMethod.Parameters.Length]; int[] outRefArgMap = syncMethod.OutRefArgMap; for (int co = 0; co < outRefArgMap.Length; co++) { args[outRefArgMap[co]] = asyncEndArgs[co]; } return args; } // ExpandAsyncEndArgsToSyncArgs
internal static void PropagateOutParameters(IMessage msg, object[] outArgs, object returnValue) { Message message = msg as Message; if (message == null) { ConstructorCallMessage constructorCallMessage = msg as ConstructorCallMessage; if (constructorCallMessage != null) { message = constructorCallMessage.GetMessage(); } } if (message == null) { throw new ArgumentException(Environment.GetResourceString("Remoting_Proxy_ExpectedOriginalMessage")); } RemotingMethodCachedData reflectionCachedData = InternalRemotingServices.GetReflectionCachedData(message.GetMethodBase()); if (outArgs != null && outArgs.Length != 0) { object[] args = message.Args; ParameterInfo[] parameters = reflectionCachedData.Parameters; foreach (int marshalRequestArg in reflectionCachedData.MarshalRequestArgMap) { ParameterInfo parameterInfo = parameters[marshalRequestArg]; if (parameterInfo.IsIn && parameterInfo.ParameterType.IsByRef && !parameterInfo.IsOut) { outArgs[marshalRequestArg] = args[marshalRequestArg]; } } if (reflectionCachedData.NonRefOutArgMap.Length != 0) { foreach (int nonRefOutArg in reflectionCachedData.NonRefOutArgMap) { Array array = args[nonRefOutArg] as Array; if (array != null) { Array sourceArray = (Array)outArgs[nonRefOutArg]; Array destinationArray = array; int length = destinationArray.Length; Array.Copy(sourceArray, destinationArray, length); } } } int[] outRefArgMap = reflectionCachedData.OutRefArgMap; if (outRefArgMap.Length != 0) { foreach (int index in outRefArgMap) { RealProxy.ValidateReturnArg(outArgs[index], parameters[index].ParameterType); } } } if ((message.GetCallType() & 15) != 1) { Type returnType = reflectionCachedData.ReturnType; if (returnType != (Type)null) { RealProxy.ValidateReturnArg(returnValue, returnType); } } message.PropagateOutParameters(outArgs, returnValue); }
public static ServerProcessing DispatchMessage( IServerChannelSinkStack sinkStack, IMessage msg, out IMessage replyMsg) { ServerProcessing processing = ServerProcessing.Complete; replyMsg = null; try { if (null == msg) { throw new ArgumentNullException("msg"); } BCLDebug.Trace("REMOTE", "Dispatching for URI " + InternalSink.GetURI(msg)); // we must switch to the target context of the object and call the context chains etc... // Currenly XContextChannel does exactly so. So this method is just a wrapper.. // Make sure that incoming calls are counted as a remote call. This way it // makes more sense on a server. IncrementRemoteCalls(); // Check if the object has been disconnected or if it is // a well known object then we have to create it lazily. ServerIdentity srvId = CheckDisconnectedOrCreateWellKnownObject(msg); // Make sure that this isn't an AppDomain object since we don't allow // calls to the AppDomain from out of process (and x-process calls // are always dispatched through this method) if (srvId.ServerType == typeof(System.AppDomain)) { throw new RemotingException( Environment.GetResourceString( "Remoting_AppDomainsCantBeCalledRemotely")); } IMethodCallMessage mcm = msg as IMethodCallMessage; if (mcm == null) { // It's a plain IMessage, so just check to make sure that the // target object implements IMessageSink and dispatch synchronously. if (!typeof(IMessageSink).IsAssignableFrom(srvId.ServerType)) { throw new RemotingException( Environment.GetResourceString( "Remoting_AppDomainsCantBeCalledRemotely")); } processing = ServerProcessing.Complete; replyMsg = ChannelServices.GetCrossContextChannelSink().SyncProcessMessage(msg); } else { // It's an IMethodCallMessage. // Check if the method is one way. Dispatch one way calls in // an asynchronous manner MethodInfo method = (MethodInfo)mcm.MethodBase; // X-process / X-machine calls should be to non-static // public methods only! Non-public or static methods can't // be called remotely. if (!IsMethodReallyPublic(method) && !RemotingServices.IsMethodAllowedRemotely(method)) { throw new RemotingException( Environment.GetResourceString( "Remoting_NonPublicOrStaticCantBeCalledRemotely")); } RemotingMethodCachedData cache = (RemotingMethodCachedData) InternalRemotingServices.GetReflectionCachedData(method); /* * FUTURE: * Dispatching asynchronously was cut from v1. We should reactivate * the following code in v1.x or v2. * * // look for async method version * MethodInfo begin; * MethodInfo end; * ServerChannelSinkStack serverSinkStack = sinkStack as ServerChannelSinkStack; * if ((sinkStack != null) && * cache.GetAsyncMethodVersion(out begin, out end)) * { * processing = ServerProcessing.Async; * IMessage asyncMsg = * new AsyncMethodCallMessageWrapper( * (IMethodCallMessage)msg, * begin, * new AsyncCallback(sinkStack.ServerCallback), * null); * serverSinkStack.AsyncMessage = asyncMsg; * serverSinkStack.AsyncEnd = end; * serverSinkStack.Message = (IMethodCallMessage)msg; * asyncMsg.Properties["__SinkStack"] = sinkStack; * * // We don't dispatch yet. That happens when the server transport sink * // eventually calls sinkStack.StoreAndDispatch(...). * } * else */ if (RemotingServices.IsOneWay(method)) { processing = ServerProcessing.OneWay; ChannelServices.GetCrossContextChannelSink().AsyncProcessMessage(msg, null); } else { // regular processing processing = ServerProcessing.Complete; if (!srvId.ServerType.IsContextful) { Object[] args = new Object[] { msg, srvId.ServerContext }; replyMsg = (IMessage)CrossContextChannel.SyncProcessMessageCallback(args); } else { replyMsg = ChannelServices.GetCrossContextChannelSink().SyncProcessMessage(msg); } } } // end of case for IMethodCallMessage } catch (Exception e) { if (processing != ServerProcessing.OneWay) { try { IMethodCallMessage mcm = (IMethodCallMessage)((msg != null)?msg:new ErrorMessage()); replyMsg = (IMessage) new ReturnMessage(e, mcm); if (msg != null) { ((ReturnMessage)replyMsg).SetLogicalCallContext( (LogicalCallContext) msg.Properties[Message.CallContextKey]); } } catch (Exception) { // Fatal exception .. ignore } } } return(processing); } // DispatchMessage
public virtual void GetObjectData(Object obj, SerializationInfo info, StreamingContext context) { if (info == null) { throw new ArgumentNullException("info"); } if ((obj != null) && (obj != _rootObj)) { (new MessageSurrogate(_ss)).GetObjectData(obj, info, context); } else { IMethodReturnMessage msg = obj as IMethodReturnMessage; if (null != msg) { if (msg.Exception == null) { String responseElementName; String responseElementNS; String returnElementName; // obtain response element name namespace MethodBase mb = msg.MethodBase; SoapMethodAttribute attr = (SoapMethodAttribute)InternalRemotingServices.GetCachedSoapAttribute(mb); responseElementName = attr.ResponseXmlElementName; responseElementNS = attr.ResponseXmlNamespace; returnElementName = attr.ReturnXmlElementName; ArgMapper mapper = new ArgMapper(msg, true /*fOut*/); Object[] args = mapper.Args; info.FullTypeName = responseElementName; info.AssemblyName = responseElementNS; Type retType = ((MethodInfo)mb).ReturnType; if (!((retType == null) || (retType == _voidType))) { info.AddValue(returnElementName, msg.ReturnValue, retType); } if (args != null) { Type[] types = mapper.ArgTypes; for (int i = 0; i < args.Length; i++) { String name; name = mapper.GetArgName(i); if ((name == null) || (name.Length == 0)) { name = "__param" + i; } info.AddValue( name, args[i], types[i].IsByRef? types[i].GetElementType():types[i]); } } } else { Object oClientIsClr = CallContext.GetData("__ClientIsClr"); bool bClientIsClr = (oClientIsClr == null) ? true:(bool)oClientIsClr; info.FullTypeName = "FormatterWrapper"; info.AssemblyName = DefaultFakeRecordAssemblyName; Exception ex = msg.Exception; StringBuilder sb = new StringBuilder(); bool bMustUnderstandError = false; while (ex != null) { if (ex.Message.StartsWith("MustUnderstand")) { bMustUnderstandError = true; } sb.Append(" **** "); sb.Append(ex.GetType().FullName); sb.Append(" - "); sb.Append(ex.Message); ex = ex.InnerException; } ServerFault serverFault = null; if (bClientIsClr) { serverFault = new ServerFault(msg.Exception); // Clr is the Client use full exception } else { serverFault = new ServerFault(msg.Exception.GetType().AssemblyQualifiedName, sb.ToString(), msg.Exception.StackTrace); } String faultType = "Server"; if (bMustUnderstandError) { faultType = "MustUnderstand"; } SoapFault soapFault = new SoapFault(faultType, sb.ToString(), null, serverFault); info.AddValue("__WrappedObject", soapFault, _soapFaultType); } } else { IMethodCallMessage mcm = (IMethodCallMessage)obj; // obtain method namespace MethodBase mb = mcm.MethodBase; String methodElementNS = SoapServices.GetXmlNamespaceForMethodCall(mb); Object[] args = mcm.InArgs; String[] names = GetInArgNames(mcm, args.Length); Type[] sig = (Type[])mcm.MethodSignature; info.FullTypeName = mcm.MethodName; info.AssemblyName = methodElementNS; RemotingMethodCachedData cache = (RemotingMethodCachedData)InternalRemotingServices.GetReflectionCachedData(mb); int[] requestArgMap = cache.MarshalRequestArgMap; BCLDebug.Assert( args != null || sig.Length == args.Length, "Signature mismatch"); for (int i = 0; i < args.Length; i++) { String paramName = null; if ((names[i] == null) || (names[i].Length == 0)) { paramName = "__param" + i; } else { paramName = names[i]; } int sigPosition = requestArgMap[i]; Type argType = null; if (sig[sigPosition].IsByRef) { argType = sig[sigPosition].GetElementType(); } else { argType = sig[sigPosition]; } info.AddValue(paramName, args[i], argType); } } } } // GetObjectData
public virtual IMessageCtrl AsyncProcessMessage( IMessage msg, IMessageSink replySink) { IMethodCallMessage mcMsg = (IMethodCallMessage)msg; IMessageCtrl retCtrl = null; IMessage retMessage = null; LogicalCallContext oldCallCtx = null; try { LogicalCallContext callCtx = (LogicalCallContext) mcMsg.Properties[Message.CallContextKey]; Object server = _server; // validate the method base if necessary VerifyIsOkToCallMethod(server, mcMsg); // install call context onto the thread, holding onto // the one that is currently on the thread oldCallCtx = CallContext.SetLogicalCallContext(callCtx); // retrieve incoming headers callCtx.PropagateIncomingHeadersToCallContext(msg); PreserveThreadPrincipalIfNecessary(callCtx, oldCallCtx); // see if this is a server message that was dispatched asynchronously ServerChannelSinkStack sinkStack = msg.Properties["__SinkStack"] as ServerChannelSinkStack; if (sinkStack != null) { sinkStack.ServerObject = server; } BCLDebug.Assert((server != null) == (!_bStatic), "Invalid state in stackbuilder sink?"); MethodBase mb = GetMethodBase(mcMsg); Object[] outArgs = null; Object ret = null; RemotingMethodCachedData methodCache = InternalRemotingServices.GetReflectionCachedData(mb); Object[] args = Message.CoerceArgs(mcMsg, methodCache.Parameters); ret = PrivateProcessMessage(mb, args, server, 0, false, out outArgs); CopyNonByrefOutArgsFromOriginalArgs(methodCache, args, ref outArgs); if (replySink != null) { // call context could be different then the one from before the call. LogicalCallContext latestCallContext = CallContext.GetLogicalCallContext(); retMessage = new ReturnMessage( ret, outArgs, (outArgs == null ? 0 : outArgs.Length), latestCallContext, mcMsg); // retrieve outgoing response headers latestCallContext.PropagateOutgoingHeadersToMessage(retMessage); replySink.SyncProcessMessage(retMessage); } } catch (Exception e) { try { if (replySink != null) { retMessage = new ReturnMessage(e, mcMsg); ((ReturnMessage)retMessage).SetLogicalCallContext( (LogicalCallContext) mcMsg.Properties[Message.CallContextKey]); replySink.SyncProcessMessage(retMessage); } } catch (Exception) { // Fatal error.. can't do anything .. // bail out silently. } } finally { // restore the call context on the thread if (oldCallCtx != null) { CallContext.SetLogicalCallContext(oldCallCtx); } } return(retCtrl); } // AsyncProcessMessage
internal void SetObjectFromSoapData(SerializationInfo info) { this.methodName = info.GetString("__methodName"); ArrayList list = (ArrayList)info.GetValue("__paramNameList", typeof(ArrayList)); Hashtable keyToNamespaceTable = (Hashtable)info.GetValue("__keyToNamespaceTable", typeof(Hashtable)); if (this.MI == null) { ArrayList argValues = new ArrayList(); ArrayList argNames = list; for (int i = 0; i < argNames.Count; i++) { argValues.Add(info.GetValue((string)argNames[i], typeof(object))); } RuntimeType t = this.ResolveType() as RuntimeType; if (t == null) { throw new RemotingException(string.Format(CultureInfo.CurrentCulture, Environment.GetResourceString("Remoting_BadType"), new object[] { this.typeName })); } this.ResolveOverloadedMethod(t, this.methodName, argNames, argValues); if (this.MI == null) { throw new RemotingException(string.Format(CultureInfo.CurrentCulture, Environment.GetResourceString("Remoting_Message_MethodMissing"), new object[] { this.methodName, this.typeName })); } } RemotingMethodCachedData reflectionCachedData = InternalRemotingServices.GetReflectionCachedData(this.MI); ParameterInfo[] parameters = reflectionCachedData.Parameters; int[] marshalRequestArgMap = reflectionCachedData.MarshalRequestArgMap; object obj2 = (this.InternalProperties == null) ? null : this.InternalProperties["__UnorderedParams"]; this.args = new object[parameters.Length]; if (((obj2 != null) && (obj2 is bool)) && ((bool)obj2)) { for (int j = 0; j < list.Count; j++) { string name = (string)list[j]; int index = -1; for (int k = 0; k < parameters.Length; k++) { if (name.Equals(parameters[k].Name)) { index = parameters[k].Position; break; } } if (index == -1) { if (!name.StartsWith("__param", StringComparison.Ordinal)) { throw new RemotingException(Environment.GetResourceString("Remoting_Message_BadSerialization")); } index = int.Parse(name.Substring(7), CultureInfo.InvariantCulture); } if (index >= this.args.Length) { throw new RemotingException(Environment.GetResourceString("Remoting_Message_BadSerialization")); } this.args[index] = Message.SoapCoerceArg(info.GetValue(name, typeof(object)), parameters[index].ParameterType, keyToNamespaceTable); } } else { for (int m = 0; m < list.Count; m++) { string str2 = (string)list[m]; this.args[marshalRequestArgMap[m]] = Message.SoapCoerceArg(info.GetValue(str2, typeof(object)), parameters[marshalRequestArgMap[m]].ParameterType, keyToNamespaceTable); } this.PopulateOutArguments(reflectionCachedData); } }