Inheritance: RealProxy, IRemotingTypeInfo
Beispiel #1
0
        [System.Security.SecurityCritical]  // auto-generated_required
        protected RealProxy(Type classToProxy, IntPtr stub, Object stubData)
        {
            if (!classToProxy.IsMarshalByRef && !classToProxy.IsInterface)
            {
                throw new ArgumentException(
                          Environment.GetResourceString("Remoting_Proxy_ProxyTypeIsNotMBR"));
            }
            Contract.EndContractBlock();

            if ((IntPtr)0 == stub)
            {
                Contract.Assert((IntPtr)0 != _defaultStub, "Default stub not set up");

                // The default stub checks for match of contexts defined by us
                stub = _defaultStub;
                // Start with a value of -1 because 0 is reserved for the default context
                stubData = _defaultStubData;
            }

            _tp = null;
            if (stubData == null)
            {
                throw new ArgumentNullException("stubdata");
            }
            _tp = RemotingServices.CreateTransparentProxy(this, classToProxy, stub, stubData);
            RemotingProxy rp = this as RemotingProxy;

            if (rp != null)
            {
                _flags |= RealProxyFlags.RemotingProxy;
            }
        }
Beispiel #2
0
        [System.Security.SecurityCritical]  // auto-generated 
        public virtual RealProxy CreateProxy(ObjRef objRef,
                                             Type serverType, 
                                             Object serverObject,
                                             Context serverContext)
        {
            RemotingProxy rp =  new RemotingProxy(serverType); 

            // If this is a serverID, set the native context field in the TP 
            if (null != serverContext) 
            {
                RealProxy.SetStubData(rp, serverContext.InternalContextID); 
            }

            if (objRef != null && objRef.GetServerIdentity().IsAllocated)
            { 
                rp.SetSrvInfo(objRef.GetServerIdentity(), objRef.GetDomainID());
            } 
 
            // Set the flag indicating that the fields of the proxy
            // have been initialized 
            rp.Initialized = true;

            // Sanity check
            Type t = serverType; 
            if (!t.IsContextful &&
                !t.IsMarshalByRef && 
                (null != serverContext)) 
            {
                throw new RemotingException( 
                    Environment.GetResourceString(
                        "Remoting_Activation_MBR_ProxyAttribute"));
            }
 
            return rp;
        } 
 internal static IConstructionReturnMessage Activate(RemotingProxy remProxy, IConstructionCallMessage ctorMsg)
 {
     IConstructionReturnMessage message = null;
     if (((ConstructorCallMessage) ctorMsg).ActivateInContext)
     {
         message = ctorMsg.Activator.Activate(ctorMsg);
         if (message.Exception != null)
         {
             throw message.Exception;
         }
         return message;
     }
     GetPropertiesFromAttributes(ctorMsg, ctorMsg.CallSiteActivationAttributes);
     GetPropertiesFromAttributes(ctorMsg, ((ConstructorCallMessage) ctorMsg).GetWOMAttributes());
     GetPropertiesFromAttributes(ctorMsg, ((ConstructorCallMessage) ctorMsg).GetTypeAttributes());
     IMethodReturnMessage message2 = (IMethodReturnMessage) Thread.CurrentContext.GetClientContextChain().SyncProcessMessage(ctorMsg);
     message = message2 as IConstructionReturnMessage;
     if (message2 == null)
     {
         throw new RemotingException(Environment.GetResourceString("Remoting_Activation_Failed"));
     }
     if (message2.Exception != null)
     {
         throw message2.Exception;
     }
     return message;
 }
Beispiel #4
0
        // Default implementation of CreateProxy creates an instance of our
        // remoting proxy
        /// <include file='doc\ProxyAttribute.uex' path='docs/doc[@for="ProxyAttribute.CreateProxy"]/*' />

        public virtual RealProxy CreateProxy(ObjRef objRef,
                                             Type serverType,
                                             Object serverObject,
                                             Context serverContext)
        {
            RemotingProxy rp = new RemotingProxy(serverType);

            // If this is a serverID, set the native context field in the TP
            if (null != serverContext)
            {
                RealProxy.SetStubData(rp, serverContext.InternalContextID);
            }

            // Set the flag indicating that the fields of the proxy
            // have been initialized
            rp.Initialized = true;

            // Sanity check
            Type t = serverType;

            if (!t.IsContextful &&
                !t.IsMarshalByRef &&
                (null != serverContext))
            {
                throw new RemotingException(
                          Environment.GetResourceString(
                              "Remoting_Activation_MBR_ProxyAttribute"));
            }

            return(rp);
        }
Beispiel #5
0
 public virtual MarshalByRefObject CreateInstance(Type serverType)
 {
                 #if !DISABLE_REMOTING
     RemotingProxy proxy = new RemotingProxy(serverType, ChannelServices.CrossContextUrl, null);
                 #else
     RemotingProxy proxy = new RemotingProxy(serverType, "", null);
                 #endif
     return((MarshalByRefObject)proxy.GetTransparentProxy());
 }
Beispiel #6
0
		public virtual MarshalByRefObject CreateInstance (Type serverType)
		{
#if MOONLIGHT
			throw new NotImplementedException ();
#else
			RemotingProxy proxy = new RemotingProxy (serverType, ChannelServices.CrossContextUrl, null);
			return (MarshalByRefObject) proxy.GetTransparentProxy();
#endif
		}
Beispiel #7
0
        public virtual MarshalByRefObject CreateInstance(Type serverType)
        {
#if MOONLIGHT
            throw new NotImplementedException();
#else
            RemotingProxy proxy = new RemotingProxy(serverType, ChannelServices.CrossContextUrl, null);
            return((MarshalByRefObject)proxy.GetTransparentProxy());
#endif
        }
Beispiel #8
0
        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;
                }
            }
        }
Beispiel #9
0
        // 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);
        }
		public static IMessage Activate (RemotingProxy proxy, ConstructionCall ctorCall)
		{
			IMessage response;
			ctorCall.SourceProxy = proxy;

			if (Thread.CurrentContext.HasExitSinks && !ctorCall.IsContextOk)
				response = Thread.CurrentContext.GetClientContextSinkChain ().SyncProcessMessage (ctorCall);
			else
				response = RemoteActivate (ctorCall);

			if (response is IConstructionReturnMessage && ((IConstructionReturnMessage)response).Exception == null && proxy.ObjectIdentity == null)
			{
				Identity identity = RemotingServices.GetMessageTargetIdentity (ctorCall);
				proxy.AttachIdentity (identity);
			}

			return response;
		}
 public virtual RealProxy CreateProxy(ObjRef objRef, Type serverType, object serverObject, Context serverContext)
 {
     RemotingProxy rp = new RemotingProxy(serverType);
     if (serverContext != null)
     {
         RealProxy.SetStubData(rp, serverContext.InternalContextID);
     }
     if ((objRef != null) && objRef.GetServerIdentity().IsAllocated)
     {
         rp.SetSrvInfo(objRef.GetServerIdentity(), objRef.GetDomainID());
     }
     rp.Initialized = true;
     Type type = serverType;
     if ((!type.IsContextful && !type.IsMarshalByRef) && (serverContext != null))
     {
         throw new RemotingException(Environment.GetResourceString("Remoting_Activation_MBR_ProxyAttribute"));
     }
     return rp;
 }
        public virtual RealProxy CreateProxy(ObjRef objRef, Type serverType, object serverObject, Context serverContext)
        {
            RemotingProxy remotingProxy = new RemotingProxy(serverType);

            if (serverContext != null)
            {
                RealProxy.SetStubData(remotingProxy, serverContext.InternalContextID);
            }
            if (objRef != null && objRef.GetServerIdentity().IsAllocated)
            {
                remotingProxy.SetSrvInfo(objRef.GetServerIdentity(), objRef.GetDomainID());
            }
            remotingProxy.Initialized = true;
            if (!serverType.IsContextful && !serverType.IsMarshalByRef && serverContext != null)
            {
                throw new RemotingException(Environment.GetResourceString("Remoting_Activation_MBR_ProxyAttribute"));
            }
            return(remotingProxy);
        }
Beispiel #13
0
        protected RealProxy(Type classToProxy, IntPtr stub, object stubData)
        {
            if (!classToProxy.IsMarshalByRef && !classToProxy.IsInterface)
            {
                throw new ArgumentException(Environment.GetResourceString("Remoting_Proxy_ProxyTypeIsNotMBR"));
            }
            if ((IntPtr)0 == stub)
            {
                stub     = RealProxy._defaultStub;
                stubData = RealProxy._defaultStubData;
            }
            this._tp = null;
            if (stubData == null)
            {
                throw new ArgumentNullException("stubdata");
            }
            this._tp = RemotingServices.CreateTransparentProxy(this, classToProxy, stub, stubData);
            RemotingProxy remotingProxy = this as RemotingProxy;

            if (remotingProxy != null)
            {
                this._flags |= RealProxyFlags.RemotingProxy;
            }
        }
        [System.Security.SecurityCritical]  // auto-generated
        internal static MarshalByRefObject CreateInstance(RuntimeType serverType)
        {
            // Use our activation implementation               
            MarshalByRefObject retObj = null;
            ConstructorCallMessage ctorCallMsg = null;
            bool bCtxOK = IsCurrentContextOK(serverType, null, ref ctorCallMsg);
            if (bCtxOK && !serverType.IsContextful)
            {
                // Marshal by ref case
                Message.DebugOut("Allocating blank marshal-by-ref object"); 
                // We create an uninitialized instance of the actual type and
                // let the regular jit-activation execute the constructor on it.
                retObj = RemotingServices.AllocateUninitializedObject(serverType);
            }
            else 
            {
                //  (context not OK) || (serverType is Contextful)
                // We always return a proxy and the jit-activation's attempt
                // to execute the constructor gets intercepted by the TP stub
                // and routed to RemotingServices.Activate() below.

                // if context *is* OK 
                // this is a contextBound type being activated for which 
                // we always create a proxy (proxies-everywhere!)

                // if context *is not* OK 
                // this could be a MarshalByRef or ContextBound type 
                // being activated outside this appDomain 
                // OR
                // this could be a ContextBound type being activated cross-ctx 

                RemotingProxy rp;
                // See if the object-type is configured for Connect (with a URL)
                retObj = (MarshalByRefObject)ConnectIfNecessary(ctorCallMsg);
                if (retObj == null)
                {
                    // not configured for connect, take the usual route of 
                    // creating a proxy
                    Message.DebugOut("Creating remoting proxy for " + 
                                 serverType.FullName + " in context " + 
                                 Thread.CurrentContext);  

                    rp = new RemotingProxy(serverType);

                    Message.DebugOut("Created remoting proxy\n");
                    retObj = (MarshalByRefObject)rp.GetTransparentProxy();
                }
                else
                {
                    Message.DebugOut("NewObj did a Connect!");
                    rp = (RemotingProxy)RemotingServices.GetRealProxy(retObj);                    
                }                    

                // Store the constructor call message in the proxy
                rp.ConstructorMessage = ctorCallMsg;

                if (!bCtxOK)
                {

                    // Chain in the context level activator now
                    ContextLevelActivator activator = new ContextLevelActivator();
                    activator.NextActivator = ctorCallMsg.Activator; 
                    ctorCallMsg.Activator = activator;
                }
                else
                {
                    // Set the flag to indicate that the activation
                    // will not be leaving the client context .. in this case
                    // the default construction level activator is enough
                    // to complete the activation process.
                    ctorCallMsg.ActivateInContext = true;
                }
            }

            return retObj;
        }
        [System.Security.SecurityCritical]  // auto-generated
        internal static Object CheckIfConnected(
            RemotingProxy proxy, IConstructionCallMessage ctorMsg)
        {
            // If we performed a connect, we must have put the URL as
            // the connectKey in the message.
            String objURL = (String)
                            ctorMsg.Properties[ConnectKey];
            Object tp = null;

            if (objURL != null)
            {   
                // We did perform a connect during IsContextOK 
                // Just get the TP from RP and return it.
                tp = (Object)proxy.GetTransparentProxy();
            } 
            // We return null if we do not recognize this proxy!
            return tp;                                            
        }
Beispiel #16
0
		internal static ClientIdentity GetOrCreateClientIdentity(ObjRef objRef, Type proxyType, out object clientProxy)
		{
			// This method looks for an identity for the given url. 
			// If an identity is not found, it creates the identity and 
			// assigns it a proxy to the remote object.

			// Creates the client sink chain for the given url or channelData.
			// It will also get the object uri from the url.

			object channelData = objRef.ChannelInfo != null ? objRef.ChannelInfo.ChannelData : null;

			string objectUri;
			IMessageSink sink = GetClientChannelSinkChain (objRef.URI, channelData, out objectUri);

			if (objectUri == null) objectUri = objRef.URI;

			lock (uri_hash)
			{
				clientProxy = null;
				string uri = GetNormalizedUri (objRef.URI);
				
				ClientIdentity identity = uri_hash [uri] as ClientIdentity;
				if (identity != null)
				{
					// Object already registered
					clientProxy = identity.ClientProxy;
					if (clientProxy != null) return identity;
					
					// The proxy has just been GCed, so its identity cannot
					// be reused. Just dispose it.
					DisposeIdentity (identity);
				}

				// Creates an identity and a proxy for the remote object

				identity = new ClientIdentity (objectUri, objRef);
				identity.ChannelSink = sink;

				// Registers the identity
				uri_hash [uri] = identity;
				
				if (proxyType != null)
				{
					RemotingProxy proxy = new RemotingProxy (proxyType, identity);
					CrossAppDomainSink cds = sink as CrossAppDomainSink;
					if (cds != null)
						proxy.SetTargetDomain (cds.TargetDomainId);

					clientProxy = proxy.GetTransparentProxy();
					identity.ClientProxy = (MarshalByRefObject) clientProxy;
				}

				return identity;
			}
		}
Beispiel #17
0
		internal static object CreateClientProxyForContextBound (Type type, object[] activationAttributes)
		{
			if (type.IsContextful)
			{
				// Look for a ProxyAttribute
				ProxyAttribute att = (ProxyAttribute) Attribute.GetCustomAttribute (type, typeof(ProxyAttribute), true);
				if (att != null)
					return att.CreateInstance (type);
			}
			RemotingProxy proxy = new RemotingProxy (type, ChannelServices.CrossContextUrl, activationAttributes);
			return proxy.GetTransparentProxy();
		}
Beispiel #18
0
		internal static object CreateClientProxy (Type objectType, string url, object[] activationAttributes)
		{
			string activationUrl = url;
			if (!activationUrl.EndsWith ("/"))
				activationUrl += "/";
			activationUrl += "RemoteActivationService.rem";

			string objectUri;
			GetClientChannelSinkChain (activationUrl, null, out objectUri);

			RemotingProxy proxy = new RemotingProxy (objectType, activationUrl, activationAttributes);
			return proxy.GetTransparentProxy();
		}
Beispiel #19
0
        public IConstructionReturnMessage InitializeServerObject(IConstructionCallMessage ctorMsg)
        {
            IConstructionReturnMessage retMsg = null;

            if (_serverObject == null)
            {
                Type svrType = GetProxiedType();
                if ((ctorMsg != null) && (ctorMsg.ActivationType != svrType))
                {
                    throw new RemotingException(
                              String.Format(
                                  Environment.GetResourceString("Remoting_Proxy_BadTypeForActivation"),
                                  svrType.FullName,
                                  ctorMsg.ActivationType));
                }

                // Create a blank object
                _serverObject = RemotingServices.AllocateUninitializedObject(svrType);

                // If the stub is the default stub, then set the server context
                // to be the current context.
                SetContextForDefaultStub();

                // OK... we are all set to run the constructor call on the uninitialized object
                MarshalByRefObject   proxy = (MarshalByRefObject)GetTransparentProxy();
                IMethodReturnMessage msg   = null;
                Exception            e     = null;
                if (null != ctorMsg)
                {
                    msg = RemotingServices.ExecuteMessage(proxy, ctorMsg);
                    e   = msg.Exception;
                }
                else
                {
                    try
                    {
                        RemotingServices.CallDefaultCtor(proxy);
                    }
                    catch (Exception excep)
                    {
                        e = excep;
                    }
                }

                // Construct a return message
                if (null == e)
                {
                    Object[]           outArgs   = (msg == null ? null : msg.OutArgs);
                    int                outLength = (null == outArgs ? 0 : outArgs.Length);
                    LogicalCallContext callCtx   = (msg == null ? null : msg.LogicalCallContext);
                    retMsg = new ConstructorReturnMessage(proxy,
                                                          outArgs, outLength,
                                                          callCtx, ctorMsg);

                    // setup identity
                    SetupIdentity();
                    RemotingProxy rp = this as RemotingProxy;
                    if (rp != null)
                    {
                        rp.Initialized = true;
                    }
                }
                else
                {
                    // Exception occurred
                    retMsg = new ConstructorReturnMessage(e, ctorMsg);
                }
            }


            return(retMsg);
        }
        /// <summary>Creates either an uninitialized <see cref="T:System.MarshalByRefObject" /> or a transparent proxy, depending on whether the specified type can exist in the current context.</summary>
        /// <returns>An uninitialized <see cref="T:System.MarshalByRefObject" /> or a transparent proxy.</returns>
        /// <param name="serverType">The object type to create an instance of. </param>
        /// <PermissionSet>
        ///   <IPermission class="System.Security.Permissions.FileIOPermission, mscorlib, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Unrestricted="true" />
        ///   <IPermission class="System.Security.Permissions.ReflectionPermission, mscorlib, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Flags="MemberAccess" />
        ///   <IPermission class="System.Security.Permissions.SecurityPermission, mscorlib, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Flags="ControlEvidence, Infrastructure" />
        /// </PermissionSet>
        public virtual MarshalByRefObject CreateInstance(Type serverType)
        {
            RemotingProxy remotingProxy = new RemotingProxy(serverType, ChannelServices.CrossContextUrl, null);

            return((MarshalByRefObject)remotingProxy.GetTransparentProxy());
        }
Beispiel #21
0
        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;
        }
 internal static MarshalByRefObject CreateInstance(RuntimeType serverType)
 {
     MarshalByRefObject transparentProxy = null;
     ConstructorCallMessage ctorCallMsg = null;
     RemotingProxy realProxy;
     bool flag = IsCurrentContextOK(serverType, null, ref ctorCallMsg);
     if (flag && !serverType.IsContextful)
     {
         return RemotingServices.AllocateUninitializedObject(serverType);
     }
     transparentProxy = (MarshalByRefObject) ConnectIfNecessary(ctorCallMsg);
     if (transparentProxy == null)
     {
         realProxy = new RemotingProxy(serverType);
         transparentProxy = (MarshalByRefObject) realProxy.GetTransparentProxy();
     }
     else
     {
         realProxy = (RemotingProxy) RemotingServices.GetRealProxy(transparentProxy);
     }
     realProxy.ConstructorMessage = ctorCallMsg;
     if (!flag)
     {
         ContextLevelActivator activator = new ContextLevelActivator {
             NextActivator = ctorCallMsg.Activator
         };
         ctorCallMsg.Activator = activator;
         return transparentProxy;
     }
     ctorCallMsg.ActivateInContext = true;
     return transparentProxy;
 }
Beispiel #23
0
        // 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"));
            }
        }
        private void PrivateInvoke(ref MessageData msgData, int type)
        {
            IMessage      reqMsg   = null;
            CallType      type2    = (CallType)type;
            IMessage      retMsg   = null;
            int           msgFlags = -1;
            RemotingProxy proxy    = null;

            if (CallType.MethodCall == type2)
            {
                Message message3 = new Message();
                message3.InitFields(msgData);
                reqMsg   = message3;
                msgFlags = message3.GetCallType();
            }
            else if (CallType.ConstructorCall == type2)
            {
                msgFlags = 0;
                proxy    = this as RemotingProxy;
                ConstructorCallMessage ccm = null;
                bool flag = false;
                if (!this.IsRemotingProxy())
                {
                    ccm = new ConstructorCallMessage(null, null, null, (RuntimeType)this.GetProxiedType());
                }
                else
                {
                    ccm = proxy.ConstructorMessage;
                    Identity identityObject = proxy.IdentityObject;
                    if (identityObject != null)
                    {
                        flag = identityObject.IsWellKnown();
                    }
                }
                if ((ccm == null) || flag)
                {
                    ccm = new ConstructorCallMessage(null, null, null, (RuntimeType)this.GetProxiedType());
                    ccm.SetFrame(msgData);
                    reqMsg = ccm;
                    if (flag)
                    {
                        proxy.ConstructorMessage = null;
                        if (ccm.ArgCount != 0)
                        {
                            throw new RemotingException(Environment.GetResourceString("Remoting_Activation_WellKnownCTOR"));
                        }
                    }
                    retMsg = new ConstructorReturnMessage((MarshalByRefObject)this.GetTransparentProxy(), null, 0, null, ccm);
                }
                else
                {
                    ccm.SetFrame(msgData);
                    reqMsg = ccm;
                }
            }
            ChannelServices.IncrementRemoteCalls();
            if (!this.IsRemotingProxy() && ((msgFlags & 2) == 2))
            {
                Message message5 = reqMsg as Message;
                retMsg = EndInvokeHelper(message5, true);
            }
            if (retMsg == null)
            {
                LogicalCallContext cctx          = null;
                Thread             currentThread = Thread.CurrentThread;
                cctx = currentThread.GetLogicalCallContext();
                this.SetCallContextInMessage(reqMsg, msgFlags, cctx);
                cctx.PropagateOutgoingHeadersToMessage(reqMsg);
                retMsg = this.Invoke(reqMsg);
                this.ReturnCallContextToThread(currentThread, retMsg, msgFlags, cctx);
                CallContext.GetLogicalCallContext().PropagateIncomingHeadersToCallContext(retMsg);
            }
            if (!this.IsRemotingProxy() && ((msgFlags & 1) == 1))
            {
                Message     m   = reqMsg as Message;
                AsyncResult ret = new AsyncResult(m);
                ret.SyncProcessMessage(retMsg);
                retMsg = new ReturnMessage(ret, null, 0, null, m);
            }
            HandleReturnMessage(reqMsg, retMsg);
            if (CallType.ConstructorCall == type2)
            {
                MarshalByRefObject         obj2     = null;
                IConstructionReturnMessage message7 = retMsg as IConstructionReturnMessage;
                if (message7 == null)
                {
                    throw new RemotingException(Environment.GetResourceString("Remoting_Proxy_BadReturnTypeForActivation"));
                }
                ConstructorReturnMessage message8 = message7 as ConstructorReturnMessage;
                if (message8 != null)
                {
                    obj2 = (MarshalByRefObject)message8.GetObject();
                    if (obj2 == null)
                    {
                        throw new RemotingException(Environment.GetResourceString("Remoting_Activation_NullReturnValue"));
                    }
                }
                else
                {
                    obj2 = (MarshalByRefObject)RemotingServices.InternalUnmarshal((ObjRef)message7.ReturnValue, this.GetTransparentProxy(), true);
                    if (obj2 == null)
                    {
                        throw new RemotingException(Environment.GetResourceString("Remoting_Activation_NullFromInternalUnmarshal"));
                    }
                }
                if (obj2 != ((MarshalByRefObject)this.GetTransparentProxy()))
                {
                    throw new RemotingException(Environment.GetResourceString("Remoting_Activation_InconsistentState"));
                }
                if (this.IsRemotingProxy())
                {
                    proxy.ConstructorMessage = null;
                }
            }
        }
Beispiel #25
0
        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;
                }
            }
        }
        [System.Security.SecurityCritical]  // auto-generated
        internal static IConstructionReturnMessage Activate(
            RemotingProxy remProxy, IConstructionCallMessage ctorMsg)
        {
            IConstructionReturnMessage ctorRetMsg = null;

            if (((ConstructorCallMessage)ctorMsg).ActivateInContext)
            {
                // The current context was approved for activation
                Contract.Assert(
                    ctorMsg.Activator.Level == ActivatorLevel.Construction,
                    "activator level must ActivatorLevel.Construction!");

                // This has to be a ContextBound type (proxies-everywhere)
                Contract.Assert(ctorMsg.ActivationType.IsContextful, 
                                "Inconsistent state during activation");

                // Ask the activator in the message to take over
                ctorRetMsg = ctorMsg.Activator.Activate(ctorMsg);

                if (ctorRetMsg.Exception != null)
                {
                    throw ctorRetMsg.Exception;
                }
            }
            else
            {
                // Client context was not approved for activation ...
                Contract.Assert(
                    ctorMsg.Activator.Level >= ActivatorLevel.Context,
                    "activator level must be at least x-context!");

                // Check with ActivationServices if we did a "Connect" with
                // a remote server during IsContextOK
                Contract.Assert(
                    ActivationServices.CheckIfConnected(remProxy, ctorMsg) == null,
                    "We shouldn't come through this path on a Connect.");                    

                // Client context was not approved for activation ...
                // This is the more elaborate (real) activation case i.e.
                // we have to go at least out of the client context to 
                // finish the work.

                // Prepare for the handoff to Activation Service

                // Ask various attributes to contribute properties
                // The attributes may chain in other activators into
                // the activation chain (to hijack/participate in
                // the activation process).
                ActivationServices.GetPropertiesFromAttributes(
                    (IConstructionCallMessage)ctorMsg, 
                    ctorMsg.CallSiteActivationAttributes);

                ActivationServices.GetPropertiesFromAttributes(
                    ctorMsg, 
                    ((ConstructorCallMessage)ctorMsg).GetWOMAttributes());

                ActivationServices.GetPropertiesFromAttributes(
                    (IConstructionCallMessage)ctorMsg, 
                ((ConstructorCallMessage)ctorMsg).GetTypeAttributes());       

                // Fetch the client context chain
                IMessageSink cliCtxChain = 
                Thread.CurrentContext.GetClientContextChain();

                // Ask the client context chain to take over from here.
                IMethodReturnMessage retMsg =  
                    (IMethodReturnMessage)
                        cliCtxChain.SyncProcessMessage(ctorMsg);

                // The return message may not be of type
                // IConstructionReturnMessage if an exception happens
                // in the sink chains.
                ctorRetMsg = retMsg as IConstructionReturnMessage;
                if (null == retMsg)
                {
                    throw new RemotingException(
                        Environment.GetResourceString(
                            "Remoting_Activation_Failed"));
                }
                else if (retMsg.Exception != null)
                {
                    throw retMsg.Exception;
                }                                
            }
            // Note: PropagateOutParameters is now handled by RealProxy
            // CallContext from retMsg should be already set by RealProxy
            Contract.Assert(
                null != ctorRetMsg, 
                "Activate returning null ConstructorReturnMessage");
                
            return ctorRetMsg;
        }
 internal static object CheckIfConnected(RemotingProxy proxy, IConstructionCallMessage ctorMsg)
 {
     string str = (string) ctorMsg.Properties["Connect"];
     object transparentProxy = null;
     if (str != null)
     {
         transparentProxy = proxy.GetTransparentProxy();
     }
     return transparentProxy;
 }
Beispiel #28
0
        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);
        }
Beispiel #29
0
		public virtual MarshalByRefObject CreateInstance (Type serverType)
		{
			RemotingProxy proxy = new RemotingProxy (serverType, ChannelServices.CrossContextUrl, null);
			return (MarshalByRefObject) proxy.GetTransparentProxy();
		}
Beispiel #30
0
        [System.Security.SecurityCritical]  // auto-generated
        private void PrivateInvoke(ref MessageData msgData, int type)
        {
            IMessage reqMsg   = null;
            CallType callType = (CallType)type;
            IMessage retMsg   = null;
            int      msgFlags = -1;

            // Used only for Construction case
            RemotingProxy rp = null;

            // Create a message object based on the type of call
            if (CallType.MethodCall == callType)
            {
                Message msg = new Message();
                msg.InitFields(msgData);
                reqMsg   = msg;
                msgFlags = msg.GetCallType();
            }
            else if (CallType.ConstructorCall == (CallType)callType)
            {
                // We use msgFlags to handle CallContext around
                // the virtual call to Invoke()
                msgFlags = Message.Sync;

                rp = this as RemotingProxy;
                ConstructorCallMessage ctorMsg = null;
                bool bIsWellKnown = false;
                if (!IsRemotingProxy())
                {
                    // Create a new constructor call message
                    // <

                    ctorMsg = new ConstructorCallMessage(null, null, null, (RuntimeType)GetProxiedType());
                }
                else
                {
                    // Extract the constructor message set in the first step of activation.
                    ctorMsg = rp.ConstructorMessage;
                    // If the proxy is a wellknown client proxy, we don't
                    // need to run the c'tor.
                    Identity id = rp.IdentityObject;
                    if (id != null)
                    {
                        bIsWellKnown = id.IsWellKnown();
                    }
                }

                if ((null == ctorMsg) || bIsWellKnown)
                {
                    // This is also used to short-circuit the activation path
                    // when we have a well known proxy that has already been
                    // initialized (there's a race condition if we don't do this).
                    //

                    // This is a special case, where we have a remoting proxy
                    // but the constructormessage hasn't been setup.
                    // so let us just bail out..
                    // this is currently used by ServicedComponent's for cross appdomain
                    // pooling: <EMAIL>Microsoft</EMAIL>
                    //
                    ctorMsg = new ConstructorCallMessage(null, null, null, (RuntimeType)GetProxiedType());
                    // Set the constructor frame info in the CCM
                    ctorMsg.SetFrame(msgData);
                    reqMsg = ctorMsg;

                    // If this was the default ctor, check that default .ctor was called.
                    if (bIsWellKnown)
                    {
                        Contract.Assert(rp != null, "RemotingProxy expected here!");
                        // Clear any cached ctorMsg on the RemotingProxy
                        rp.ConstructorMessage = null;

                        // We did execute a Connect. Throw if the client
                        // code is also trying to use a non-default constructor at
                        // the same time.
                        if (ctorMsg.ArgCount != 0)
                        {
                            throw new RemotingException(
                                      Environment.GetResourceString(
                                          "Remoting_Activation_WellKnownCTOR"));
                        }
                    }

                    // Create a constructor return message
                    retMsg =
                        new ConstructorReturnMessage((MarshalByRefObject)GetTransparentProxy(),
                                                     null,
                                                     0,
                                                     null,
                                                     ctorMsg);
                }
                else
                {
                    // Set the constructor frame info in the CCM
                    ctorMsg.SetFrame(msgData);
                    reqMsg = ctorMsg;
                }
            }
            else
            {
                Contract.Assert(false, "Unknown call type");
            }

            // Make sure that outgoing remote calls are counted.
            ChannelServices.IncrementRemoteCalls();

            // For non-remoting proxies, EndAsync should not call Invoke()
            // because the proxy cannot support Async and the call has already
            // finished executing in BeginAsync
            if (!IsRemotingProxy() &&
                ((msgFlags & Message.EndAsync) == Message.EndAsync))
            {
                Message msg = reqMsg as Message;
                retMsg = EndInvokeHelper(msg, true);
                Contract.Assert(null != retMsg, "null != retMsg");
            }

            // Invoke
            Contract.Assert(null != reqMsg, "null != reqMsg");
            if (null == retMsg)
            {
                // NOTE: there are cases where we setup a return message
                // and we don't want the activation call to go through
                // refer to the note above for ServicedComponents and Cross Appdomain
                // pooling

                LogicalCallContext cctx          = null;
                Thread             currentThread = Thread.CurrentThread;
                // Pick up or clone the call context from the thread
                // and install it in the reqMsg as appropriate
                cctx = currentThread.GetMutableExecutionContext().LogicalCallContext;
                SetCallContextInMessage(reqMsg, msgFlags, cctx);

                // Add the outgoing "Header"'s to the message.
                cctx.PropagateOutgoingHeadersToMessage(reqMsg);
                retMsg = Invoke(reqMsg);

                // Get the call context returned and set it on the thread
                ReturnCallContextToThread(currentThread, retMsg, msgFlags, cctx);

                // Pull response "Header"'s out of the message
                Thread.CurrentThread.GetMutableExecutionContext().LogicalCallContext.PropagateIncomingHeadersToCallContext(retMsg);
            }

            if (!IsRemotingProxy() &&
                ((msgFlags & Message.BeginAsync) == Message.BeginAsync))
            {
                // This was a begin-async on a non-Remoting Proxy. For V-1 they
                // cannot support Async and end up doing a Sync call. We need
                // to fill up here to make the call look like async to
                // the caller.
                // Create the async result to return
                Message     msg = reqMsg as Message;
                AsyncResult ar  = new AsyncResult(msg);
                // Tell the async result that the call has actually completed
                // so it can hold on to the return message.
                ar.SyncProcessMessage(retMsg);
                // create a returnMessage to propagate just the asyncResult back
                // to the caller's stack.
                retMsg = new ReturnMessage(ar, null, 0, null /*cctx*/, msg);
            }

            // Propagate out parameters
            HandleReturnMessage(reqMsg, retMsg);

            // For constructor calls do some extra bookkeeping
            if (CallType.ConstructorCall == callType)
            {
                // NOTE: It is the responsiblity of the callee to propagate
                // the out parameters

                // Everything went well, we are ready to return
                // a proxy to the caller
                // Extract the return value
                MarshalByRefObject         retObj     = null;
                IConstructionReturnMessage ctorRetMsg = retMsg as IConstructionReturnMessage;
                if (null == ctorRetMsg)
                {
                    throw new RemotingException(
                              Environment.GetResourceString("Remoting_Proxy_BadReturnTypeForActivation"));
                }

                ConstructorReturnMessage crm = ctorRetMsg as ConstructorReturnMessage;
                if (null != crm)
                {
                    // If return message is of type ConstructorReturnMessage
                    // this is an in-appDomain activation. So no unmarshaling
                    // needed.

                    retObj = (MarshalByRefObject)crm.GetObject();
                    if (retObj == null)
                    {
                        throw new RemotingException(
                                  Environment.GetResourceString("Remoting_Activation_NullReturnValue"));
                    }
                }
                else
                {
                    // Fetch the objRef out of the returned message and unmarshal it
                    retObj = (MarshalByRefObject)RemotingServices.InternalUnmarshal(
                        (ObjRef)ctorRetMsg.ReturnValue,
                        GetTransparentProxy(),
                        true /*fRefine*/);

                    if (retObj == null)
                    {
                        throw new RemotingException(
                                  Environment.GetResourceString("Remoting_Activation_NullFromInternalUnmarshal"));
                    }
                }

                if (retObj != (MarshalByRefObject)GetTransparentProxy())
                {
                    throw new RemotingException(
                              Environment.GetResourceString(
                                  "Remoting_Activation_InconsistentState"));
                }

                if (IsRemotingProxy())
                {
                    // Clear any cached ctorMsg on the RemotingProxy
                    rp.ConstructorMessage = null;
                }
            }
        }
Beispiel #31
0
        // Private method invoked by the transparent proxy
        private void PrivateInvoke(ref MessageData msgData, int type)
        {
            IMessage reqMsg   = null;
            CallType callType = (CallType)type;
            IMessage retMsg   = null;
            int      msgFlags = -1;

            // Create a message object based on the type of call
            if (CallType.MethodCall == callType)
            {
                Message msg = new Message();
                msg.InitFields(msgData);
                reqMsg   = msg;
                msgFlags = msg.GetCallType();
            }
            else if (CallType.ConstructorCall == (CallType)callType)
            {
                // We use msgFlags to handle CallContext around
                // the virtual call to Invoke()
                msgFlags = Message.Sync;

                ConstructorCallMessage ctorMsg = null;
                RemotingProxy          rp      = this as RemotingProxy;
                if (null == rp)
                {
                    // Create a new constructor call message
                    ctorMsg = new ConstructorCallMessage(null, null, null, GetProxiedType());
                }
                else
                {
                    // Extract the constructor message set in the first step of activation.
                    ctorMsg = rp.ConstructorMessage;
                }

                // If the proxy is a wellknown client proxy, we don't need to run the c'tor.
                bool bIsWellKnown = false;
                if (rp != null)
                {
                    Identity id = rp.IdentityObject;
                    if (id != null)
                    {
                        bIsWellKnown = id.IsWellKnown();
                    }
                }

                if ((null == ctorMsg) || bIsWellKnown)
                {
                    // This is also used to short-circuit the activation path
                    // when we have a well known proxy that has already been
                    // initialized (there's a race condition if we don't do this).
                    //

                    // This is a special case, where we have a remoting proxy
                    // but the constructormessage hasn't been setup.
                    // so let us just bail out..
                    // this is currently used by ServicedComponent's for cross appdomain
                    // pooling:
                    //

                    /*
                     * ProxyAttribute pa = null;
                     * BCLDebug.Assert(((pa = ActivationServices.GetProxyAttribute(GetProxiedType()) is Object) || true);
                     * BCLDebug.Assert(pa != null && pa.GetType() != typeof(ProxyAttribute));
                     */
                    ctorMsg = new ConstructorCallMessage(null, null, null, GetProxiedType());
                    // Set the constructor frame info in the CCM
                    ctorMsg.SetFrame(msgData);
                    reqMsg = ctorMsg;

                    // If this was the default ctor, check that default .ctor was called.
                    if (bIsWellKnown)
                    {
                        // We did execute a Connect. Throw if the client
                        // code is also trying to use a non-default constructor at
                        // the same time.
                        if (ctorMsg.ArgCount != 0)
                        {
                            throw new RemotingException(
                                      Environment.GetResourceString(
                                          "Remoting_Activation_WellKnownCTOR"));
                        }
                    }

                    // Create a constructor return message
                    retMsg =
                        new ConstructorReturnMessage((MarshalByRefObject)GetTransparentProxy(),
                                                     null,
                                                     0,
                                                     null,
                                                     ctorMsg);
                }
                else
                {
                    // Set the constructor frame info in the CCM
                    ctorMsg.SetFrame(msgData);
                    reqMsg = ctorMsg;
                }
            }
            else
            {
                BCLDebug.Assert(false, "Unknown call type");
            }

            // Make sure that outgoing remote calls are counted.
            ChannelServices.IncrementRemoteCalls();


            // Invoke
            BCLDebug.Assert(null != reqMsg, "null != reqMsg");
            if (null == retMsg)
            {
                // NOTE: there are cases where we setup a return message
                // and we don't want the activation call to go through
                // refer to the note above for ServicedComponents and Cross Appdomain
                // pooling

                LogicalCallContext cctx          = null;
                Thread             currentThread = Thread.CurrentThread;
                // Pick up or clone the call context from the thread
                // and install it in the reqMsg as appropriate
                cctx = currentThread.GetLogicalCallContext();
                SetCallContextInMessage(reqMsg, msgFlags, cctx);

                // Add the outgoing "Header"'s to the message.
                cctx.PropagateOutgoingHeadersToMessage(reqMsg);

                retMsg = Invoke(reqMsg);

                // Get the call context returned and set it on the thread
                ReturnCallContextToThread(currentThread, retMsg, msgFlags);

                // Pull response "Header"'s out of the message
                CallContext.GetLogicalCallContext().PropagateIncomingHeadersToCallContext(retMsg);
            }

            // Propagate out parameters
            HandleReturnMessage(reqMsg, retMsg);

            // For constructor calls do some extra bookkeeping
            if (CallType.ConstructorCall == callType)
            {
                // NOTE: It is the responsiblity of the callee to propagate
                // the out parameters

                // Everything went well, we are ready to return
                // a proxy to the caller
                // Extract the return value
                MarshalByRefObject         retObj     = null;
                IConstructionReturnMessage ctorRetMsg = retMsg as IConstructionReturnMessage;
                if (null == ctorRetMsg)
                {
                    throw new RemotingException(
                              Environment.GetResourceString("Remoting_Proxy_BadReturnTypeForActivation"));
                }

                ConstructorReturnMessage crm = ctorRetMsg as ConstructorReturnMessage;
                if (null != crm)
                {
                    retObj = (MarshalByRefObject)crm.GetObject();
                    if (retObj == null)
                    {
                        throw new RemotingException(
                                  Environment.GetResourceString("Remoting_Activation_NullReturnValue"));
                    }
                }
                else
                {
                    // Fetch the objRef out of the returned message and unmarshal it
                    retObj = (MarshalByRefObject)RemotingServices.InternalUnmarshal(
                        (ObjRef)ctorRetMsg.ReturnValue,
                        GetTransparentProxy(),
                        true /*fRefine*/);

                    if (retObj == null)
                    {
                        throw new RemotingException(
                                  Environment.GetResourceString("Remoting_Activation_NullFromInternalUnmarshal"));
                    }
                }

                if (retObj != (MarshalByRefObject)GetTransparentProxy())
                {
                    throw new RemotingException(
                              Environment.GetResourceString(
                                  "Remoting_Activation_InconsistentState"));
                }
            }
        }