private static void Invoke(object NotUsed, ref MessageData msgData) { Message reqMcmMsg = new Message(); reqMcmMsg.InitFields(msgData); Delegate thisPtr = reqMcmMsg.GetThisPtr() as Delegate; if (thisPtr == null) { throw new RemotingException(Environment.GetResourceString("Remoting_Default")); } RemotingProxy realProxy = (RemotingProxy)RemotingServices.GetRealProxy(thisPtr.Target); if (realProxy != null) { realProxy.InternalInvoke(reqMcmMsg, true, reqMcmMsg.GetCallType()); } else { int callType = reqMcmMsg.GetCallType(); switch (callType) { case 1: case 9: { reqMcmMsg.Properties[Message.CallContextKey] = CallContext.GetLogicalCallContext().Clone(); AsyncResult retVal = new AsyncResult(reqMcmMsg); AgileAsyncWorkerItem state = new AgileAsyncWorkerItem(reqMcmMsg, ((callType & 8) != 0) ? null : retVal, thisPtr.Target); ThreadPool.QueueUserWorkItem(new WaitCallback(AgileAsyncWorkerItem.ThreadPoolCallBack), state); if ((callType & 8) != 0) { retVal.SyncProcessMessage(null); } reqMcmMsg.PropagateOutParameters(null, retVal); break; } case 2: RealProxy.EndInvokeHelper(reqMcmMsg, false); return; case 10: break; default: return; } } }
// Token: 0x06005742 RID: 22338 RVA: 0x00133030 File Offset: 0x00131230 private static void Invoke(object NotUsed, ref MessageData msgData) { Message message = new Message(); message.InitFields(msgData); object thisPtr = message.GetThisPtr(); Delegate @delegate; if ((@delegate = (thisPtr as Delegate)) == null) { throw new RemotingException(Environment.GetResourceString("Remoting_Default")); } RemotingProxy remotingProxy = (RemotingProxy)RemotingServices.GetRealProxy(@delegate.Target); if (remotingProxy != null) { remotingProxy.InternalInvoke(message, true, message.GetCallType()); return; } int callType = message.GetCallType(); if (callType <= 2) { if (callType != 1) { if (callType != 2) { return; } RealProxy.EndInvokeHelper(message, false); return; } } else if (callType != 9) { return; } message.Properties[Message.CallContextKey] = Thread.CurrentThread.GetMutableExecutionContext().LogicalCallContext.Clone(); AsyncResult asyncResult = new AsyncResult(message); AgileAsyncWorkerItem state = new AgileAsyncWorkerItem(message, ((callType & 8) != 0) ? null : asyncResult, @delegate.Target); ThreadPool.QueueUserWorkItem(new WaitCallback(AgileAsyncWorkerItem.ThreadPoolCallBack), state); if ((callType & 8) != 0) { asyncResult.SyncProcessMessage(null); } message.PropagateOutParameters(null, asyncResult); }
internal virtual IMessage InternalInvoke(IMethodCallMessage reqMcmMsg, bool useDispatchMessage, int callType) { Message message1 = reqMcmMsg as Message; if (message1 == null && callType != 0) { throw new RemotingException(Environment.GetResourceString("Remoting_Proxy_InvalidCallType")); } IMessage message2 = (IMessage)null; Thread currentThread = Thread.CurrentThread; LogicalCallContext logicalCallContext = currentThread.GetMutableExecutionContext().LogicalCallContext; Identity identityObject = this.IdentityObject; ServerIdentity serverIdentity = identityObject as ServerIdentity; if (serverIdentity != null && identityObject.IsFullyDisconnected()) { throw new ArgumentException(Environment.GetResourceString("Remoting_ServerObjectNotFound", (object)reqMcmMsg.Uri)); } MethodBase methodBase = reqMcmMsg.MethodBase; if ((MethodBase)RemotingProxy._getTypeMethod == methodBase) { return((IMessage) new ReturnMessage((object)this.GetProxiedType(), (object[])null, 0, logicalCallContext, reqMcmMsg)); } if ((MethodBase)RemotingProxy._getHashCodeMethod == methodBase) { return((IMessage) new ReturnMessage((object)identityObject.GetHashCode(), (object[])null, 0, logicalCallContext, reqMcmMsg)); } if (identityObject.ChannelSink == null) { IMessageSink chnlSink = (IMessageSink)null; IMessageSink envoySink = (IMessageSink)null; if (!identityObject.ObjectRef.IsObjRefLite()) { RemotingServices.CreateEnvoyAndChannelSinks((MarshalByRefObject)null, identityObject.ObjectRef, out chnlSink, out envoySink); } else { RemotingServices.CreateEnvoyAndChannelSinks(identityObject.ObjURI, (object)null, out chnlSink, out envoySink); } RemotingServices.SetEnvoyAndChannelSinks(identityObject, chnlSink, envoySink); if (identityObject.ChannelSink == null) { throw new RemotingException(Environment.GetResourceString("Remoting_Proxy_NoChannelSink")); } } IInternalMessage internalMessage = (IInternalMessage)reqMcmMsg; internalMessage.IdentityObject = identityObject; if (serverIdentity != null) { internalMessage.ServerIdentityObject = serverIdentity; } else { internalMessage.SetURI(identityObject.URI); } switch (callType) { case 0: bool bSkippingContextChain = false; Context currentContextInternal = currentThread.GetCurrentContextInternal(); IMessageSink ms = identityObject.EnvoyChain; if (currentContextInternal.IsDefaultContext && ms is EnvoyTerminatorSink) { bSkippingContextChain = true; ms = identityObject.ChannelSink; } message2 = RemotingProxy.CallProcessMessage(ms, (IMessage)reqMcmMsg, identityObject.ProxySideDynamicSinks, currentThread, currentContextInternal, bSkippingContextChain); break; case 1: case 9: LogicalCallContext callContext1 = (LogicalCallContext)logicalCallContext.Clone(); internalMessage.SetCallContext(callContext1); AsyncResult asyncResult = new AsyncResult(message1); this.InternalInvokeAsync((IMessageSink)asyncResult, message1, useDispatchMessage, callType); message2 = (IMessage) new ReturnMessage((object)asyncResult, (object[])null, 0, (LogicalCallContext)null, (IMethodCallMessage)message1); break; case 2: message2 = RealProxy.EndInvokeHelper(message1, true); break; case 8: LogicalCallContext callContext2 = (LogicalCallContext)logicalCallContext.Clone(); internalMessage.SetCallContext(callContext2); this.InternalInvokeAsync((IMessageSink)null, message1, useDispatchMessage, callType); message2 = (IMessage) new ReturnMessage((object)null, (object[])null, 0, (LogicalCallContext)null, reqMcmMsg); break; case 10: message2 = (IMessage) new ReturnMessage((object)null, (object[])null, 0, (LogicalCallContext)null, reqMcmMsg); break; } return(message2); }
private void PrivateInvoke(ref MessageData msgData, int type) { IMessage message1 = (IMessage)null; CallType callType = (CallType)type; IMessage message2 = (IMessage)null; int msgFlags = -1; RemotingProxy remotingProxy = (RemotingProxy)null; if (CallType.MethodCall == callType) { Message message3 = new Message(); MessageData msgData1 = msgData; message3.InitFields(msgData1); message1 = (IMessage)message3; msgFlags = message3.GetCallType(); } else if (CallType.ConstructorCall == callType) { msgFlags = 0; remotingProxy = this as RemotingProxy; bool flag = false; ConstructorCallMessage constructorCallMessage1; if (!this.IsRemotingProxy()) { constructorCallMessage1 = new ConstructorCallMessage((object[])null, (object[])null, (object[])null, (RuntimeType)this.GetProxiedType()); } else { constructorCallMessage1 = remotingProxy.ConstructorMessage; Identity identityObject = remotingProxy.IdentityObject; if (identityObject != null) { flag = identityObject.IsWellKnown(); } } if (constructorCallMessage1 == null | flag) { ConstructorCallMessage constructorCallMessage2 = new ConstructorCallMessage((object[])null, (object[])null, (object[])null, (RuntimeType)this.GetProxiedType()); constructorCallMessage2.SetFrame(msgData); message1 = (IMessage)constructorCallMessage2; if (flag) { remotingProxy.ConstructorMessage = (ConstructorCallMessage)null; if (constructorCallMessage2.ArgCount != 0) { throw new RemotingException(Environment.GetResourceString("Remoting_Activation_WellKnownCTOR")); } } message2 = (IMessage) new ConstructorReturnMessage((MarshalByRefObject)this.GetTransparentProxy(), (object[])null, 0, (LogicalCallContext)null, (IConstructionCallMessage)constructorCallMessage2); } else { constructorCallMessage1.SetFrame(msgData); message1 = (IMessage)constructorCallMessage1; } } ChannelServices.IncrementRemoteCalls(); if (!this.IsRemotingProxy() && (msgFlags & 2) == 2) { message2 = RealProxy.EndInvokeHelper(message1 as Message, true); } if (message2 == null) { Thread currentThread = Thread.CurrentThread; LogicalCallContext logicalCallContext = currentThread.GetMutableExecutionContext().LogicalCallContext; this.SetCallContextInMessage(message1, msgFlags, logicalCallContext); logicalCallContext.PropagateOutgoingHeadersToMessage(message1); message2 = this.Invoke(message1); this.ReturnCallContextToThread(currentThread, message2, msgFlags, logicalCallContext); Thread.CurrentThread.GetMutableExecutionContext().LogicalCallContext.PropagateIncomingHeadersToCallContext(message2); } if (!this.IsRemotingProxy() && (msgFlags & 1) == 1) { Message m = message1 as Message; AsyncResult asyncResult = new AsyncResult(m); IMessage msg = message2; asyncResult.SyncProcessMessage(msg); // ISSUE: variable of the null type __Null local1 = null; int outArgsCount = 0; // ISSUE: variable of the null type __Null local2 = null; Message message3 = m; message2 = (IMessage) new ReturnMessage((object)asyncResult, (object[])local1, outArgsCount, (LogicalCallContext)local2, (IMethodCallMessage)message3); } RealProxy.HandleReturnMessage(message1, message2); if (CallType.ConstructorCall != callType) { return; } IConstructionReturnMessage constructionReturnMessage = message2 as IConstructionReturnMessage; if (constructionReturnMessage == null) { throw new RemotingException(Environment.GetResourceString("Remoting_Proxy_BadReturnTypeForActivation")); } ConstructorReturnMessage constructorReturnMessage = constructionReturnMessage as ConstructorReturnMessage; MarshalByRefObject marshalByRefObject; if (constructorReturnMessage != null) { marshalByRefObject = (MarshalByRefObject)constructorReturnMessage.GetObject(); if (marshalByRefObject == null) { throw new RemotingException(Environment.GetResourceString("Remoting_Activation_NullReturnValue")); } } else { marshalByRefObject = (MarshalByRefObject)RemotingServices.InternalUnmarshal((ObjRef)constructionReturnMessage.ReturnValue, this.GetTransparentProxy(), true); if (marshalByRefObject == null) { throw new RemotingException(Environment.GetResourceString("Remoting_Activation_NullFromInternalUnmarshal")); } } if (marshalByRefObject != (MarshalByRefObject)this.GetTransparentProxy()) { throw new RemotingException(Environment.GetResourceString("Remoting_Activation_InconsistentState")); } if (!this.IsRemotingProxy()) { return; } remotingProxy.ConstructorMessage = (ConstructorCallMessage)null; }
// Invoke for case where call is in the same context as the server object // (This special static method is used for AsyncDelegate-s ... this is called // directly from the EE) private static void Invoke(Object NotUsed, ref MessageData msgData) { Message m = new Message(); m.InitFields(msgData); Object thisPtr = m.GetThisPtr(); Delegate d; if ((d = thisPtr as Delegate) != null) { RemotingProxy rp = (RemotingProxy) RemotingServices.GetRealProxy(d.Target); if (rp != null) { rp.InternalInvoke(m, true, m.GetCallType()); } else { int callType = m.GetCallType(); AsyncResult ar; switch (callType) { case Message.BeginAsync: case Message.BeginAsync | Message.OneWay: // pick up call context from the thread m.Properties[Message.CallContextKey] = CallContext.GetLogicalCallContext().Clone(); ar = new AsyncResult(m); AgileAsyncWorkerItem workItem = new AgileAsyncWorkerItem( m, ((callType & Message.OneWay) != 0) ? null : ar, d.Target); ThreadPool.QueueUserWorkItem( new WaitCallback( AgileAsyncWorkerItem.ThreadPoolCallBack), workItem); if ((callType & Message.OneWay) != 0) { ar.SyncProcessMessage(null); } m.PropagateOutParameters(null, ar); break; case (Message.EndAsync | Message.OneWay): return; case Message.EndAsync: // This will also merge back the call context // onto the thread that called EndAsync RealProxy.EndInvokeHelper(m, false); break; default: BCLDebug.Assert( false, "Should never be here. Sync delegate code for agile object ended up in remoting"); break; } } } else { // Static invoke called with incorrect this pointer ... throw new RemotingException( Environment.GetResourceString( "Remoting_Default")); } }
} // Invoke // This is called for all remoted calls on a TP except Ctors // The method called may be Sync, Async or OneWay(special case of Async) // In the Async case we come here for both BeginInvoke & EndInvoke internal virtual IMessage InternalInvoke( IMethodCallMessage reqMcmMsg, bool useDispatchMessage, int callType) { Message reqMsg = reqMcmMsg as Message; if ((reqMsg == null) && (callType != Message.Sync)) { // Only the synchronous call type is supported for messages that // aren't of type Message. throw new RemotingException( Environment.GetResourceString("Remoting_Proxy_InvalidCallType")); } IMessage retMsg = null; Thread currentThread = Thread.CurrentThread; // pick up call context from the thread LogicalCallContext cctx = currentThread.GetLogicalCallContext(); Identity idObj = IdentityObject; ServerIdentity serverID = idObj as ServerIdentity; if ((null != serverID) && idObj.IsFullyDisconnected()) { throw new ArgumentException( String.Format(Environment.GetResourceString("Remoting_ServerObjectNotFound"), reqMcmMsg.Uri)); } // Short-circuit calls to Object::GetType and Object::GetHashCode MethodBase mb = reqMcmMsg.MethodBase; if (_getTypeMethod == mb) { // Time to load the true type of the remote object.... Type t = GetProxiedType(); return(new ReturnMessage(t, null, 0, null /*cctx*/, reqMcmMsg)); } if (_getHashCodeMethod == mb) { int hashCode = idObj.GetHashCode(); return(new ReturnMessage(hashCode, null, 0, null /*cctx*/, reqMcmMsg)); } // check for channel sink if (idObj.ChannelSink == null) { throw new RemotingException( Environment.GetResourceString("Remoting_Proxy_NoChannelSink")); } // Set the identity in the message object IInternalMessage iim = (IInternalMessage)reqMcmMsg; iim.IdentityObject = idObj; if (null != serverID) { Message.DebugOut("Setting serveridentity on message \n"); iim.ServerIdentityObject = serverID; } else { // We need to set the URI only for identities that // are not the server identities. The uri is used to // dispatch methods for objects outside the appdomain. // Inside the appdomain (xcontext case) we dispatch // by getting the server object from the server identity. iim.SetURI(idObj.URI); } Message.DebugOut("InternalInvoke. Dispatching based on class type\n"); AsyncResult ar = null; switch (callType) { case Message.Sync: Message.DebugOut("RemotingProxy.Invoke Call: SyncProcessMsg\n"); BCLDebug.Assert(!useDispatchMessage, "!useDispatchMessage"); bool bSkipContextChain = false; Context currentContext = currentThread.GetCurrentContextInternal(); IMessageSink nextSink = idObj.EnvoyChain; // if we are in the default context, there can be no // client context chain, so we can skip the intermediate // calls if there are no envoy sinks if (currentContext.IsDefaultContext) { if (nextSink is EnvoyTerminatorSink) { bSkipContextChain = true; // jump directly to the channel sink nextSink = idObj.ChannelSink; } } retMsg = CallProcessMessage(nextSink, reqMcmMsg, idObj.ProxySideDynamicSinks, currentThread, currentContext, bSkipContextChain); break; case Message.BeginAsync: case Message.BeginAsync | Message.OneWay: // For async calls we clone the call context from the thread // This is a limited clone (we dont deep copy the user data) cctx = (LogicalCallContext)cctx.Clone(); iim.SetCallContext(cctx); ar = new AsyncResult(reqMsg); InternalInvokeAsync(ar, reqMsg, useDispatchMessage, callType); Message.DebugOut("Propagate out params for BeginAsync\n"); retMsg = new ReturnMessage(ar, null, 0, null /*cctx*/, reqMsg); break; case Message.OneWay: // For async calls we clone the call context from the thread // This is a limited clone (we dont deep copy the user data) cctx = (LogicalCallContext)cctx.Clone(); iim.SetCallContext(cctx); InternalInvokeAsync(null, reqMsg, useDispatchMessage, callType); retMsg = new ReturnMessage(null, null, 0, null /*cctx*/, reqMcmMsg); break; case (Message.EndAsync | Message.OneWay): retMsg = new ReturnMessage(null, null, 0, null /*cctx*/, reqMcmMsg); break; case Message.EndAsync: // For endAsync, we merge back the returned callContext // into the thread's callContext retMsg = RealProxy.EndInvokeHelper(reqMsg, true); break; } return(retMsg); }
private void PrivateInvoke(ref MessageData msgData, int type) { IMessage message = null; IMessage message2 = null; int num = -1; RemotingProxy remotingProxy = null; if (1 == type) { Message message3 = new Message(); message3.InitFields(msgData); message = message3; num = message3.GetCallType(); } else if (2 == type) { num = 0; remotingProxy = (this as RemotingProxy); bool flag = false; ConstructorCallMessage constructorCallMessage; if (!this.IsRemotingProxy()) { constructorCallMessage = new ConstructorCallMessage(null, null, null, (RuntimeType)this.GetProxiedType()); } else { constructorCallMessage = remotingProxy.ConstructorMessage; Identity identityObject = remotingProxy.IdentityObject; if (identityObject != null) { flag = identityObject.IsWellKnown(); } } if (constructorCallMessage == null || flag) { constructorCallMessage = new ConstructorCallMessage(null, null, null, (RuntimeType)this.GetProxiedType()); constructorCallMessage.SetFrame(msgData); message = constructorCallMessage; if (flag) { remotingProxy.ConstructorMessage = null; if (constructorCallMessage.ArgCount != 0) { throw new RemotingException(Environment.GetResourceString("Remoting_Activation_WellKnownCTOR")); } } message2 = new ConstructorReturnMessage((MarshalByRefObject)this.GetTransparentProxy(), null, 0, null, constructorCallMessage); } else { constructorCallMessage.SetFrame(msgData); message = constructorCallMessage; } } ChannelServices.IncrementRemoteCalls(); if (!this.IsRemotingProxy() && (num & 2) == 2) { Message reqMsg = message as Message; message2 = RealProxy.EndInvokeHelper(reqMsg, true); } if (message2 == null) { Thread currentThread = Thread.CurrentThread; LogicalCallContext logicalCallContext = currentThread.GetMutableExecutionContext().LogicalCallContext; this.SetCallContextInMessage(message, num, logicalCallContext); logicalCallContext.PropagateOutgoingHeadersToMessage(message); message2 = this.Invoke(message); this.ReturnCallContextToThread(currentThread, message2, num, logicalCallContext); Thread.CurrentThread.GetMutableExecutionContext().LogicalCallContext.PropagateIncomingHeadersToCallContext(message2); } if (!this.IsRemotingProxy() && (num & 1) == 1) { Message message4 = message as Message; AsyncResult asyncResult = new AsyncResult(message4); asyncResult.SyncProcessMessage(message2); message2 = new ReturnMessage(asyncResult, null, 0, null, message4); } RealProxy.HandleReturnMessage(message, message2); if (2 == type) { IConstructionReturnMessage constructionReturnMessage = message2 as IConstructionReturnMessage; if (constructionReturnMessage == null) { throw new RemotingException(Environment.GetResourceString("Remoting_Proxy_BadReturnTypeForActivation")); } ConstructorReturnMessage constructorReturnMessage = constructionReturnMessage as ConstructorReturnMessage; MarshalByRefObject marshalByRefObject; if (constructorReturnMessage != null) { marshalByRefObject = (MarshalByRefObject)constructorReturnMessage.GetObject(); if (marshalByRefObject == null) { throw new RemotingException(Environment.GetResourceString("Remoting_Activation_NullReturnValue")); } } else { marshalByRefObject = (MarshalByRefObject)RemotingServices.InternalUnmarshal((ObjRef)constructionReturnMessage.ReturnValue, this.GetTransparentProxy(), true); if (marshalByRefObject == null) { throw new RemotingException(Environment.GetResourceString("Remoting_Activation_NullFromInternalUnmarshal")); } } if (marshalByRefObject != (MarshalByRefObject)this.GetTransparentProxy()) { throw new RemotingException(Environment.GetResourceString("Remoting_Activation_InconsistentState")); } if (this.IsRemotingProxy()) { remotingProxy.ConstructorMessage = null; } } }
internal virtual IMessage InternalInvoke(IMethodCallMessage reqMcmMsg, bool useDispatchMessage, int callType) { Message m = reqMcmMsg as Message; if ((m == null) && (callType != 0)) { throw new RemotingException(Environment.GetResourceString("Remoting_Proxy_InvalidCallType")); } IMessage message2 = null; Thread currentThread = Thread.CurrentThread; LogicalCallContext logicalCallContext = currentThread.GetLogicalCallContext(); Identity identityObject = this.IdentityObject; ServerIdentity identity2 = identityObject as ServerIdentity; if ((identity2 != null) && identityObject.IsFullyDisconnected()) { throw new ArgumentException(Environment.GetResourceString("Remoting_ServerObjectNotFound", new object[] { reqMcmMsg.Uri })); } MethodBase methodBase = reqMcmMsg.MethodBase; if (_getTypeMethod == methodBase) { return(new ReturnMessage(base.GetProxiedType(), null, 0, logicalCallContext, reqMcmMsg)); } if (_getHashCodeMethod == methodBase) { return(new ReturnMessage(identityObject.GetHashCode(), null, 0, logicalCallContext, reqMcmMsg)); } if (identityObject.ChannelSink == null) { IMessageSink chnlSink = null; IMessageSink envoySink = null; if (!identityObject.ObjectRef.IsObjRefLite()) { RemotingServices.CreateEnvoyAndChannelSinks(null, identityObject.ObjectRef, out chnlSink, out envoySink); } else { RemotingServices.CreateEnvoyAndChannelSinks(identityObject.ObjURI, null, out chnlSink, out envoySink); } RemotingServices.SetEnvoyAndChannelSinks(identityObject, chnlSink, envoySink); if (identityObject.ChannelSink == null) { throw new RemotingException(Environment.GetResourceString("Remoting_Proxy_NoChannelSink")); } } IInternalMessage message3 = (IInternalMessage)reqMcmMsg; message3.IdentityObject = identityObject; if (identity2 != null) { message3.ServerIdentityObject = identity2; } else { message3.SetURI(identityObject.URI); } AsyncResult ar = null; switch (callType) { case 0: { bool bSkippingContextChain = false; Context currentContextInternal = currentThread.GetCurrentContextInternal(); IMessageSink envoyChain = identityObject.EnvoyChain; if (currentContextInternal.IsDefaultContext && (envoyChain is EnvoyTerminatorSink)) { bSkippingContextChain = true; envoyChain = identityObject.ChannelSink; } return(CallProcessMessage(envoyChain, reqMcmMsg, identityObject.ProxySideDynamicSinks, currentThread, currentContextInternal, bSkippingContextChain)); } case 1: case 9: logicalCallContext = (LogicalCallContext)logicalCallContext.Clone(); message3.SetCallContext(logicalCallContext); ar = new AsyncResult(m); this.InternalInvokeAsync(ar, m, useDispatchMessage, callType); return(new ReturnMessage(ar, null, 0, null, m)); case 2: return(RealProxy.EndInvokeHelper(m, true)); case 3: case 4: case 5: case 6: case 7: return(message2); case 8: logicalCallContext = (LogicalCallContext)logicalCallContext.Clone(); message3.SetCallContext(logicalCallContext); this.InternalInvokeAsync(null, m, useDispatchMessage, callType); return(new ReturnMessage(null, null, 0, null, reqMcmMsg)); case 10: return(new ReturnMessage(null, null, 0, null, reqMcmMsg)); } return(message2); }