private static void VerifyIsOkToCallMethod(object server, IMethodMessage msg) { bool flag = false; MarshalByRefObject marshalByRefObject = server as MarshalByRefObject; if (marshalByRefObject == null) { return; } bool fServer; Identity identity = MarshalByRefObject.GetIdentity(marshalByRefObject, out fServer); if (identity != null) { ServerIdentity serverIdentity = identity as ServerIdentity; if (serverIdentity != null && serverIdentity.MarshaledAsSpecificType) { Type serverType = serverIdentity.ServerType; if (serverType != (Type)null) { MethodBase methodBase = StackBuilderSink.GetMethodBase(msg); RuntimeType reflectedType = (RuntimeType)methodBase.DeclaringType; if ((Type)reflectedType != serverType && !reflectedType.IsAssignableFrom(serverType)) { throw new RemotingException(string.Format((IFormatProvider)CultureInfo.CurrentCulture, Environment.GetResourceString("Remoting_InvalidCallingType"), (object)methodBase.DeclaringType.FullName, (object)serverType.FullName)); } if (reflectedType.IsInterface) { StackBuilderSink.VerifyNotIRemoteDispatch(reflectedType); } flag = true; } } } if (flag) { return; } RuntimeType reflectedType1 = (RuntimeType)StackBuilderSink.GetMethodBase(msg).ReflectedType; if (!reflectedType1.IsInterface) { if (!reflectedType1.IsInstanceOfType((object)marshalByRefObject)) { throw new RemotingException(string.Format((IFormatProvider)CultureInfo.CurrentCulture, Environment.GetResourceString("Remoting_InvalidCallingType"), (object)reflectedType1.FullName, (object)marshalByRefObject.GetType().FullName)); } } else { StackBuilderSink.VerifyNotIRemoteDispatch(reflectedType1); } }
internal ServerIdentity(MarshalByRefObject obj, Context serverCtx) : base(obj is ContextBoundObject) { if (obj != null) { if (!RemotingServices.IsTransparentProxy(obj)) { this._srvType = obj.GetType(); } else { this._srvType = RemotingServices.GetRealProxy(obj).GetProxiedType(); } } this._srvCtx = serverCtx; this._serverObjectChain = null; this._stackBuilderSink = null; }
// Creates a new server identity. This form is used by RemotingServices.Wrap // internal ServerIdentity(MarshalByRefObject obj, Context serverCtx) : base(obj is ContextBoundObject) { if(null != obj) { if(!RemotingServices.IsTransparentProxy(obj)) { _srvType = obj.GetType(); } else { RealProxy rp = RemotingServices.GetRealProxy(obj); _srvType = rp.GetProxiedType(); } } _srvCtx = serverCtx; _serverObjectChain = null; _stackBuilderSink = null; _refCount = 0; }
internal static object ActivateWithMessage(Type serverType, IMessage msg, ServerIdentity srvIdToBind, out Exception e) { object obj2 = null; e = null; obj2 = RemotingServices.AllocateUninitializedObject(serverType); object proxy = null; if (serverType.IsContextful) { if (msg is ConstructorCallMessage) { proxy = ((ConstructorCallMessage) msg).GetThisPtr(); } else { proxy = null; } proxy = RemotingServices.Wrap((ContextBoundObject) obj2, proxy, false); } else { if (Thread.CurrentContext != Context.DefaultContext) { throw new RemotingException(Environment.GetResourceString("Remoting_Activation_Failed")); } proxy = obj2; } IMessageSink sink = new StackBuilderSink(proxy); IMethodReturnMessage message = (IMethodReturnMessage) sink.SyncProcessMessage(msg); if (message.Exception == null) { if (serverType.IsContextful) { return RemotingServices.Wrap((ContextBoundObject) obj2); } return obj2; } e = message.Exception; return null; }
internal IMessageSink CreateServerObjectSinkChain (MarshalByRefObject obj, bool forceInternalExecute) { IMessageSink objectSink = new StackBuilderSink (obj, forceInternalExecute); objectSink = new ServerObjectTerminatorSink (objectSink); objectSink = new Lifetime.LeaseSink (objectSink); if (context_properties != null) { // Contribute object sinks in reverse order for (int n = context_properties.Count-1; n >= 0; n--) { IContextProperty prop = (IContextProperty) context_properties[n]; IContributeObjectSink contributor = prop as IContributeObjectSink; if (contributor != null) objectSink = contributor.GetObjectSink (obj, objectSink); } } return objectSink; }
[System.Security.SecurityCritical] // auto-generated 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.MethodHandle, 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
[System.Security.SecurityCritical] // auto-generated_required public static IMethodReturnMessage ExecuteMessage(MarshalByRefObject target, IMethodCallMessage reqMsg) { // Argument validation if(null == target) { throw new ArgumentNullException("target"); } Contract.EndContractBlock(); RealProxy rp = GetRealProxy(target); // Check for context match if( rp is RemotingProxy && !rp.DoContextsMatch() ) { throw new RemotingException( Environment.GetResourceString("Remoting_Proxy_WrongContext")); } // Dispatch the message StackBuilderSink dispatcher = new StackBuilderSink(target); // dispatch the message IMethodReturnMessage retMsg = (IMethodReturnMessage)dispatcher.SyncProcessMessage(reqMsg, 0, true); return retMsg; } // ExecuteMessage
internal ServerObjectTerminatorSink(MarshalByRefObject srvObj) { this._stackBuilderSink = new StackBuilderSink(srvObj); }
internal ServerObjectTerminatorSink(MarshalByRefObject srvObj) { _stackBuilderSink = new StackBuilderSink(srvObj); }
public virtual IMessage SyncProcessMessage(IMessage msg) { IMessage message = InternalSink.ValidateMessage(msg); if (message != null) { return(message); } IMethodCallMessage methodCallMessage = msg as IMethodCallMessage; LogicalCallContext logicalCallContext = null; LogicalCallContext logicalCallContext2 = Thread.CurrentThread.GetMutableExecutionContext().LogicalCallContext; object data = logicalCallContext2.GetData("__xADCall"); bool flag = false; IMessage message2; try { object server = this._server; StackBuilderSink.VerifyIsOkToCallMethod(server, methodCallMessage); LogicalCallContext logicalCallContext3; if (methodCallMessage != null) { logicalCallContext3 = methodCallMessage.LogicalCallContext; } else { logicalCallContext3 = (LogicalCallContext)msg.Properties["__CallContext"]; } logicalCallContext = CallContext.SetLogicalCallContext(logicalCallContext3); flag = true; logicalCallContext3.PropagateIncomingHeadersToCallContext(msg); StackBuilderSink.PreserveThreadPrincipalIfNecessary(logicalCallContext3, logicalCallContext); if (this.IsOKToStackBlt(methodCallMessage, server) && ((Message)methodCallMessage).Dispatch(server)) { message2 = new StackBasedReturnMessage(); ((StackBasedReturnMessage)message2).InitFields((Message)methodCallMessage); LogicalCallContext logicalCallContext4 = Thread.CurrentThread.GetMutableExecutionContext().LogicalCallContext; logicalCallContext4.PropagateOutgoingHeadersToMessage(message2); ((StackBasedReturnMessage)message2).SetLogicalCallContext(logicalCallContext4); } else { MethodBase methodBase = StackBuilderSink.GetMethodBase(methodCallMessage); object[] array = null; RemotingMethodCachedData reflectionCachedData = InternalRemotingServices.GetReflectionCachedData(methodBase); object[] args = Message.CoerceArgs(methodCallMessage, reflectionCachedData.Parameters); object ret = this.PrivateProcessMessage(methodBase.MethodHandle, args, server, out array); this.CopyNonByrefOutArgsFromOriginalArgs(reflectionCachedData, args, ref array); LogicalCallContext logicalCallContext5 = Thread.CurrentThread.GetMutableExecutionContext().LogicalCallContext; if (data != null && (bool)data && logicalCallContext5 != null) { logicalCallContext5.RemovePrincipalIfNotSerializable(); } message2 = new ReturnMessage(ret, array, (array == null) ? 0 : array.Length, logicalCallContext5, methodCallMessage); logicalCallContext5.PropagateOutgoingHeadersToMessage(message2); CallContext.SetLogicalCallContext(logicalCallContext); } } catch (Exception e) { message2 = new ReturnMessage(e, methodCallMessage); ((ReturnMessage)message2).SetLogicalCallContext(methodCallMessage.LogicalCallContext); if (flag) { CallContext.SetLogicalCallContext(logicalCallContext); } } return(message2); }
public virtual IMessageCtrl AsyncProcessMessage(IMessage msg, IMessageSink replySink) { IMethodCallMessage methodCallMessage = (IMethodCallMessage)msg; IMessageCtrl result = null; IMessage message = null; LogicalCallContext logicalCallContext = null; bool flag = false; try { try { LogicalCallContext logicalCallContext2 = (LogicalCallContext)methodCallMessage.Properties[Message.CallContextKey]; object server = this._server; StackBuilderSink.VerifyIsOkToCallMethod(server, methodCallMessage); logicalCallContext = CallContext.SetLogicalCallContext(logicalCallContext2); flag = true; logicalCallContext2.PropagateIncomingHeadersToCallContext(msg); StackBuilderSink.PreserveThreadPrincipalIfNecessary(logicalCallContext2, logicalCallContext); ServerChannelSinkStack serverChannelSinkStack = msg.Properties["__SinkStack"] as ServerChannelSinkStack; if (serverChannelSinkStack != null) { serverChannelSinkStack.ServerObject = server; } MethodBase methodBase = StackBuilderSink.GetMethodBase(methodCallMessage); object[] array = null; RemotingMethodCachedData reflectionCachedData = InternalRemotingServices.GetReflectionCachedData(methodBase); object[] args = Message.CoerceArgs(methodCallMessage, reflectionCachedData.Parameters); object ret = this.PrivateProcessMessage(methodBase.MethodHandle, args, server, out array); this.CopyNonByrefOutArgsFromOriginalArgs(reflectionCachedData, args, ref array); if (replySink != null) { LogicalCallContext logicalCallContext3 = Thread.CurrentThread.GetMutableExecutionContext().LogicalCallContext; if (logicalCallContext3 != null) { logicalCallContext3.RemovePrincipalIfNotSerializable(); } message = new ReturnMessage(ret, array, (array == null) ? 0 : array.Length, logicalCallContext3, methodCallMessage); logicalCallContext3.PropagateOutgoingHeadersToMessage(message); } } catch (Exception e) { if (replySink != null) { message = new ReturnMessage(e, methodCallMessage); ((ReturnMessage)message).SetLogicalCallContext((LogicalCallContext)methodCallMessage.Properties[Message.CallContextKey]); } } finally { if (replySink != null) { replySink.SyncProcessMessage(message); } } } finally { if (flag) { CallContext.SetLogicalCallContext(logicalCallContext); } } return(result); }
public static IMethodReturnMessage ExecuteMessage(MarshalByRefObject target, IMethodCallMessage reqMsg) { if (target == null) { throw new ArgumentNullException("target"); } RealProxy realProxy = GetRealProxy(target); if ((realProxy is RemotingProxy) && !realProxy.DoContextsMatch()) { throw new RemotingException(Environment.GetResourceString("Remoting_Proxy_WrongContext")); } StackBuilderSink sink = new StackBuilderSink(target); return (IMethodReturnMessage) sink.SyncProcessMessage(reqMsg, 0, true); }
public virtual IMessage SyncProcessMessage(IMessage msg) { IMessage message = InternalSink.ValidateMessage(msg); if (message != null) { return(message); } IMethodCallMessage methodCallMessage = msg as IMethodCallMessage; LogicalCallContext logicalCallContext1 = (LogicalCallContext)null; object data = Thread.CurrentThread.GetMutableExecutionContext().LogicalCallContext.GetData("__xADCall"); bool flag = false; IMessage msg1; try { object obj = this._server; StackBuilderSink.VerifyIsOkToCallMethod(obj, (IMethodMessage)methodCallMessage); LogicalCallContext logicalCallContext2 = methodCallMessage == null ? (LogicalCallContext)msg.Properties[(object)"__CallContext"] : methodCallMessage.LogicalCallContext; logicalCallContext1 = CallContext.SetLogicalCallContext(logicalCallContext2); flag = true; logicalCallContext2.PropagateIncomingHeadersToCallContext(msg); StackBuilderSink.PreserveThreadPrincipalIfNecessary(logicalCallContext2, logicalCallContext1); if (this.IsOKToStackBlt((IMethodMessage)methodCallMessage, obj) && ((Message)methodCallMessage).Dispatch(obj)) { msg1 = (IMessage) new StackBasedReturnMessage(); ((StackBasedReturnMessage)msg1).InitFields((Message)methodCallMessage); LogicalCallContext logicalCallContext3 = Thread.CurrentThread.GetMutableExecutionContext().LogicalCallContext; logicalCallContext3.PropagateOutgoingHeadersToMessage(msg1); ((StackBasedReturnMessage)msg1).SetLogicalCallContext(logicalCallContext3); } else { MethodBase methodBase = StackBuilderSink.GetMethodBase((IMethodMessage)methodCallMessage); object[] outArgs1 = (object[])null; RemotingMethodCachedData reflectionCachedData = InternalRemotingServices.GetReflectionCachedData(methodBase); object[] args = Message.CoerceArgs((IMethodMessage)methodCallMessage, reflectionCachedData.Parameters); object ret = this.PrivateProcessMessage(methodBase.MethodHandle, args, obj, out outArgs1); this.CopyNonByrefOutArgsFromOriginalArgs(reflectionCachedData, args, ref outArgs1); LogicalCallContext logicalCallContext3 = Thread.CurrentThread.GetMutableExecutionContext().LogicalCallContext; if (data != null && (bool)data && logicalCallContext3 != null) { logicalCallContext3.RemovePrincipalIfNotSerializable(); } object[] outArgs2 = outArgs1; int outArgsCount = outArgs2 == null ? 0 : outArgs1.Length; LogicalCallContext callCtx = logicalCallContext3; IMethodCallMessage mcm = methodCallMessage; msg1 = (IMessage) new ReturnMessage(ret, outArgs2, outArgsCount, callCtx, mcm); logicalCallContext3.PropagateOutgoingHeadersToMessage(msg1); CallContext.SetLogicalCallContext(logicalCallContext1); } } catch (Exception ex) { IMethodCallMessage mcm = methodCallMessage; msg1 = (IMessage) new ReturnMessage(ex, mcm); ((ReturnMessage)msg1).SetLogicalCallContext(methodCallMessage.LogicalCallContext); if (flag) { CallContext.SetLogicalCallContext(logicalCallContext1); } } return(msg1); }
public virtual IMessageCtrl AsyncProcessMessage(IMessage msg, IMessageSink replySink) { IMethodCallMessage mcm1 = (IMethodCallMessage)msg; IMessageCtrl messageCtrl = (IMessageCtrl)null; IMessage msg1 = (IMessage)null; LogicalCallContext callCtx1 = (LogicalCallContext)null; bool flag = false; try { try { LogicalCallContext logicalCallContext1 = (LogicalCallContext)mcm1.Properties[(object)Message.CallContextKey]; object server = this._server; StackBuilderSink.VerifyIsOkToCallMethod(server, (IMethodMessage)mcm1); callCtx1 = CallContext.SetLogicalCallContext(logicalCallContext1); flag = true; IMessage msg2 = msg; logicalCallContext1.PropagateIncomingHeadersToCallContext(msg2); LogicalCallContext threadCallContext = callCtx1; StackBuilderSink.PreserveThreadPrincipalIfNecessary(logicalCallContext1, threadCallContext); ServerChannelSinkStack channelSinkStack = msg.Properties[(object)"__SinkStack"] as ServerChannelSinkStack; if (channelSinkStack != null) { channelSinkStack.ServerObject = server; } MethodBase methodBase = StackBuilderSink.GetMethodBase((IMethodMessage)mcm1); object[] outArgs1 = (object[])null; RemotingMethodCachedData reflectionCachedData = InternalRemotingServices.GetReflectionCachedData(methodBase); object[] args = Message.CoerceArgs((IMethodMessage)mcm1, reflectionCachedData.Parameters); object obj = this.PrivateProcessMessage(methodBase.MethodHandle, args, server, out outArgs1); this.CopyNonByrefOutArgsFromOriginalArgs(reflectionCachedData, args, ref outArgs1); if (replySink != null) { LogicalCallContext logicalCallContext2 = Thread.CurrentThread.GetMutableExecutionContext().LogicalCallContext; if (logicalCallContext2 != null) { logicalCallContext2.RemovePrincipalIfNotSerializable(); } object ret = obj; object[] outArgs2 = outArgs1; int outArgsCount = outArgs2 == null ? 0 : outArgs1.Length; LogicalCallContext callCtx2 = logicalCallContext2; IMethodCallMessage mcm2 = mcm1; msg1 = (IMessage) new ReturnMessage(ret, outArgs2, outArgsCount, callCtx2, mcm2); logicalCallContext2.PropagateOutgoingHeadersToMessage(msg1); } } catch (Exception ex) { if (replySink != null) { msg1 = (IMessage) new ReturnMessage(ex, mcm1); ((ReturnMessage)msg1).SetLogicalCallContext((LogicalCallContext)mcm1.Properties[(object)Message.CallContextKey]); } } finally { if (replySink != null) { replySink.SyncProcessMessage(msg1); } } } finally { if (flag) { CallContext.SetLogicalCallContext(callCtx1); } } return(messageCtrl); }
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); } }