public override object GetRealObject(StreamingContext context)
        {
            RealProxy proxy = new RemoteServicedComponentProxy(this._serverType, this._pUnk, false);

            this._rp = proxy;
            return((MarshalByRefObject)proxy.GetTransparentProxy());
        }
Example #2
0
        /// <include file='doc\ServicedComponent.uex' path='docs/doc[@for="ServicedComponent.DisposeObject"]/*' />
        public static void DisposeObject(ServicedComponent sc)
        {
            RealProxy rp = RemotingServices.GetRealProxy(sc);

            if (rp is ServicedComponentProxy)
            {
                DBG.Info(DBG.SC, "DisposeObject(): Disposing ServicedComponentProxy");

                ServicedComponentProxy scp = (ServicedComponentProxy)rp;

                RemotingServices.Disconnect(sc);

                // dispose the actual proxy
                scp.Dispose(true);
            }
            else if (rp is RemoteServicedComponentProxy)
            {
                DBG.Info(DBG.SC, "DisposeObject(): Disposing RemoteServicedComponentProxy");

                RemoteServicedComponentProxy rscp = (RemoteServicedComponentProxy)rp;

                // dispose the remote instance first

                sc.Dispose();

                // then dispose the local proxy

                rscp.Dispose(true);
            }
            else     // We're off in magic land, with no proxy of our own.
            {
                sc.Dispose();
            }
        }
        public override void GetObjectData(SerializationInfo info, StreamingContext context)
        {
            ComponentServices.InitializeRemotingChannels();
            if (info == null)
            {
                throw new ArgumentNullException("info");
            }
            object data = CallContext.GetData("__ClientIsClr");

            if ((data != null) && ((bool)data))
            {
                RemoteServicedComponentProxy proxy = this._rp as RemoteServicedComponentProxy;
                if (proxy != null)
                {
                    RemotingServices.Marshal((MarshalByRefObject)proxy.RemotingIntermediary.GetTransparentProxy(), null, null).GetObjectData(info, context);
                }
                else
                {
                    base.GetObjectData(info, context);
                }
            }
            else
            {
                base.GetObjectData(info, context);
                info.SetType(typeof(ServicedComponentMarshaler));
                info.AddValue("servertype", this._rp.GetProxiedType());
                byte[] dCOMBuffer = ComponentServices.GetDCOMBuffer((MarshalByRefObject)this._rp.GetTransparentProxy());
                if (dCOMBuffer != null)
                {
                    info.AddValue("dcomInfo", dCOMBuffer);
                }
            }
        }
Example #4
0
        private RealProxy UnmarshalRemoteReference()
        {
            DBG.Info(DBG.SC, "SCM: UnmarshalRemoteReference()");
            IntPtr    pUnk = IntPtr.Zero;
            RealProxy rp   = null;

            try
            {
                _fUnMarshaled = true;
                if (buffer != null)
                {
                    pUnk = Thunk.Proxy.UnmarshalObject(buffer);
                }

                // set up a remote serviced component proxy
                rp = new RemoteServicedComponentProxy(servertype, pUnk, false);
            }
            finally
            {
                // now get rid of the pUnk
                if (pUnk != IntPtr.Zero)
                {
                    Marshal.Release(pUnk);
                }
                // if we have the dcom buffer get rid of it
                buffer = null;
            }

            return(rp);
        }
Example #5
0
        // copied from ServicedComponentMarshaler above directly
        // IF YOU MAK ANY CHANGES TO THIS, KEEP THE OTHER COPY IN SYNC
        public override void GetObjectData(SerializationInfo info, StreamingContext context)
        {
            DBG.Info(DBG.SC, "FSCM: GetObjectData");
            ComponentServices.InitializeRemotingChannels();
            if (info == null)
            {
                throw new ArgumentNullException("info");
            }

            // Check to see if this is a remoting channel, if so, then we
            // should use the standard objref marshal (cause we're going over SOAP
            // or another remoting channel).
            object oClientIsClr = CallContext.GetData("__ClientIsClr");

            DBG.Info(DBG.SC, "FSCM: GetObjectData: oClientIsClr = " + oClientIsClr);
            bool bUseStandardObjRef = (oClientIsClr == null)?false:(bool)oClientIsClr;

            if (bUseStandardObjRef)
            {
                RemoteServicedComponentProxy rscp = _rp as RemoteServicedComponentProxy;
                if (rscp != null)
                {
                    DBG.Info(DBG.SC, "FSCM: GetObjectData: intermediary objref");
                    ObjRef std = RemotingServices.Marshal((MarshalByRefObject)(rscp.RemotingIntermediary.GetTransparentProxy()), null, null);
                    std.GetObjectData(info, context);
                }
                else
                {
                    DBG.Info(DBG.SC, "FSCM: GetObjectData: Using standard objref");
                    base.GetObjectData(info, context);
                }
            }
            else
            {
                DBG.Info(DBG.SC, "FSCM: GetObjectData: Using custom objref");
                base.GetObjectData(info, context);

                //*** base.GetObjectData sets the type to be itself
                // now wack the type to be us
                info.SetType(typeof(ServicedComponentMarshaler));

                DBG.Assert(_rp != null, "_rp is null");

                info.AddValue("servertype", _rp.GetProxiedType());

                byte[] dcomBuffer = ComponentServices.GetDCOMBuffer((MarshalByRefObject)_rp.GetTransparentProxy());

                DBG.Assert(dcomBuffer != null, "dcomBuffer is null");

                if (dcomBuffer != null)
                {
                    info.AddValue("dcomInfo", dcomBuffer);
                }
            }
        }
Example #6
0
        public override Object GetRealObject(StreamingContext context)
        {
            DBG.Info(DBG.SC, "FSCM: GetRealObject");
            DBG.Assert(_pUnk != IntPtr.Zero, "pUnk is zero!");
            DBG.Assert(_serverType != null, "_serverType is null!");

            RealProxy rp = new RemoteServicedComponentProxy(_serverType, _pUnk, false);

            _rp = rp;

            return((MarshalByRefObject)rp.GetTransparentProxy());
        }
Example #7
0
        public static void DisposeObject(ServicedComponent sc)
        {
            RealProxy realProxy = RemotingServices.GetRealProxy(sc);

            if (realProxy is ServicedComponentProxy)
            {
                ServicedComponentProxy proxy2 = (ServicedComponentProxy)realProxy;
                RemotingServices.Disconnect(sc);
                proxy2.Dispose(true);
            }
            else if (realProxy is RemoteServicedComponentProxy)
            {
                RemoteServicedComponentProxy proxy3 = (RemoteServicedComponentProxy)realProxy;
                sc.Dispose();
                proxy3.Dispose(true);
            }
            else
            {
                sc.Dispose();
            }
        }
 private RealProxy UnmarshalRemoteReference()
 {
     IntPtr zero = IntPtr.Zero;
     RealProxy proxy = null;
     try
     {
         this._fUnMarshaled = true;
         if (this.buffer != null)
         {
             zero = Proxy.UnmarshalObject(this.buffer);
         }
         proxy = new RemoteServicedComponentProxy(this.servertype, zero, false);
     }
     finally
     {
         if (zero != IntPtr.Zero)
         {
             Marshal.Release(zero);
         }
         this.buffer = null;
     }
     return proxy;
 }
        private RealProxy UnmarshalRemoteReference()
        {
            IntPtr    zero  = IntPtr.Zero;
            RealProxy proxy = null;

            try
            {
                this._fUnMarshaled = true;
                if (this.buffer != null)
                {
                    zero = Proxy.UnmarshalObject(this.buffer);
                }
                proxy = new RemoteServicedComponentProxy(this.servertype, zero, false);
            }
            finally
            {
                if (zero != IntPtr.Zero)
                {
                    Marshal.Release(zero);
                }
                this.buffer = null;
            }
            return(proxy);
        }
Example #10
0
        public override MarshalByRefObject CreateInstance(Type serverType)
        {
            // Platform.Assert(Platform.W2K, "ServicedComponent");

            RealProxy          rp = null;
            MarshalByRefObject mo = null;

            DBG.Info(DBG.SC, "SCPA.CreateInstance(" + serverType + ") for managed request");


            ServicedComponentProxy.CleanupQueues(true);

            // First check if the type is configured to be activated remotely or is a well
            // known remote type.
            if ((null != RemotingConfiguration.IsWellKnownClientType(serverType)) ||
                (null != RemotingConfiguration.IsRemotelyActivatedClientType(serverType)))
            {
                // It is configured for remote activation. Ask remoting services to do the
                // job of creating a remoting proxy and returning it.
                mo = base.CreateInstance(serverType);
                rp = RemotingServices.GetRealProxy(mo);
            }
            else
            {
                bool   bIsAnotherProcess = false;
                string uri         = "";
                bool   bEventClass = ServicedComponentInfo.IsTypeEventSource(serverType);
                IntPtr pUnk        = Thunk.Proxy.CoCreateObject(serverType, !bEventClass, ref bIsAnotherProcess, ref uri);
                if (pUnk != IntPtr.Zero)
                {
                    try {
                        // TODO:  Get rid of this useless foreknowledge requirement
                        // Is there a way we can tell by QI'ing this guy if he's
                        // an event class (or something else we need to artificially
                        // wrap?
                        if (bEventClass)
                        {
                            // events and queued components use RemoteServicedComponentProxy
                            // set up a TP & Remote ServicedComponentProxy pair
                            rp = new RemoteServicedComponentProxy(serverType, pUnk, true);
                            mo = (MarshalByRefObject)rp.GetTransparentProxy();
                        }
                        else
                        {
                            if (bIsAnotherProcess)              // a-ha, we know it should be a RSCP now !!!!
                            {
                                FastRSCPObjRef oref = new FastRSCPObjRef(pUnk, serverType, uri);
                                mo = (MarshalByRefObject)RemotingServices.Unmarshal(oref);

                                DBG.Assert(mo != null, "RemotingServices.Unmarshal returned null!");
                                DBG.Assert(RemotingServices.GetRealProxy(mo) is RemoteServicedComponentProxy, "RemotingServices.Unmarshal did not return an RSCP!");
                            }
                            else        // bummer, this will give us back a SCP
                            {
                                mo = (MarshalByRefObject)Marshal.GetObjectForIUnknown(pUnk);

                                DBG.Info(DBG.SC, "ret = " + mo.GetType());
                                DBG.Info(DBG.SC, "st = " + serverType);
                                DBG.Info(DBG.SC, "rt == sc = " + (mo.GetType() == serverType));
                                DBG.Info(DBG.SC, "instanceof = " + serverType.IsInstanceOfType(mo));

                                if (!(serverType.IsInstanceOfType(mo)))
                                {
                                    throw new InvalidCastException(Resource.FormatString("ServicedComponentException_UnexpectedType", serverType, mo.GetType()));
                                }

                                rp = RemotingServices.GetRealProxy(mo);
                                if (!(rp is ServicedComponentProxy) && !(rp is RemoteServicedComponentProxy))
                                {
                                    // in cross-appdomain scenario, we get back a RemotingProxy, SetCOMIUnknown has not been made on our server!
                                    ServicedComponent sc = (ServicedComponent)mo;
                                    sc.DoSetCOMIUnknown(pUnk);
                                }
                            }
                        }
                    }
                    finally
                    {
                        Marshal.Release(pUnk);
                    }
                }
            }

            if (rp is ServicedComponentProxy)
            {
                // Here, we tell the server proxy that it needs to filter out
                // constructor calls:  We only need to do this if
                // the proxy lives in the same context as the caller,
                // otherwise we'll get an Invoke call and can do the
                // filtering automagically:
                ServicedComponentProxy scp = (ServicedComponentProxy)rp;
                if (scp.HomeToken == Thunk.Proxy.GetCurrentContextToken())
                {
                    scp.FilterConstructors();
                }
            }

            DBG.Assert(mo is ServicedComponent, " CoCI returned an invalid object type");
            DBG.Info(DBG.SC, "SCPA.CreateInstance done.");
            return(mo);
        }
        public override MarshalByRefObject CreateInstance(Type serverType)
        {
            RealProxy          realProxy        = null;
            MarshalByRefObject transparentProxy = null;

            ServicedComponentProxy.CleanupQueues(false);
            if ((RemotingConfiguration.IsWellKnownClientType(serverType) != null) || (RemotingConfiguration.IsRemotelyActivatedClientType(serverType) != null))
            {
                transparentProxy = base.CreateInstance(serverType);
                realProxy        = RemotingServices.GetRealProxy(transparentProxy);
            }
            else
            {
                bool   bIsAnotherProcess = false;
                string uri   = "";
                bool   flag2 = ServicedComponentInfo.IsTypeEventSource(serverType);
                IntPtr pUnk  = Proxy.CoCreateObject(serverType, !flag2, ref bIsAnotherProcess, ref uri);
                if (pUnk != IntPtr.Zero)
                {
                    try
                    {
                        if (flag2)
                        {
                            realProxy        = new RemoteServicedComponentProxy(serverType, pUnk, true);
                            transparentProxy = (MarshalByRefObject)realProxy.GetTransparentProxy();
                        }
                        else
                        {
                            bool flag3 = (RemotingConfiguration.IsWellKnownClientType(serverType) != null) || (null != RemotingConfiguration.IsRemotelyActivatedClientType(serverType));
                            if (bIsAnotherProcess && !flag3)
                            {
                                FastRSCPObjRef objectRef = new FastRSCPObjRef(pUnk, serverType, uri);
                                transparentProxy = (MarshalByRefObject)RemotingServices.Unmarshal(objectRef);
                            }
                            else
                            {
                                transparentProxy = (MarshalByRefObject)Marshal.GetObjectForIUnknown(pUnk);
                                if (!serverType.IsInstanceOfType(transparentProxy))
                                {
                                    throw new InvalidCastException(Resource.FormatString("ServicedComponentException_UnexpectedType", serverType, transparentProxy.GetType()));
                                }
                                realProxy = RemotingServices.GetRealProxy(transparentProxy);
                                if ((!bIsAnotherProcess && !(realProxy is ServicedComponentProxy)) && !(realProxy is RemoteServicedComponentProxy))
                                {
                                    ((ServicedComponent)transparentProxy).DoSetCOMIUnknown(pUnk);
                                }
                            }
                        }
                    }
                    finally
                    {
                        Marshal.Release(pUnk);
                    }
                }
            }
            if (realProxy is ServicedComponentProxy)
            {
                ServicedComponentProxy proxy2 = (ServicedComponentProxy)realProxy;
                if (proxy2.HomeToken == Proxy.GetCurrentContextToken())
                {
                    proxy2.FilterConstructors();
                }
            }
            return(transparentProxy);
        }