Beispiel #1
0
        public static void SetObjectUriForMarshal(MarshalByRefObject obj, string uri)
        {
            if (IsTransparentProxy(obj))
            {
                RealProxy proxy    = RemotingServices.GetRealProxy(obj);
                Identity  identity = proxy.ObjectIdentity;

                if (identity != null && !(identity is ServerIdentity) && !proxy.GetProxiedType().IsContextful)
                {
                    throw new RemotingException("SetObjectUriForMarshal method should only be called for MarshalByRefObjects that exist in the current AppDomain.");
                }
            }

            Marshal(obj, uri);
        }
 internal ServerIdentity(MarshalByRefObject obj, Context serverCtx) : base(obj is ContextBoundObject)
 {
     if (obj != null)
     {
         if (!RemotingServices.IsTransparentProxy(obj))
         {
             this._srvType = obj.GetType();
         }
         else
         {
             RealProxy realProxy = RemotingServices.GetRealProxy(obj);
             this._srvType = realProxy.GetProxiedType();
         }
     }
     this._srvCtx            = serverCtx;
     this._serverObjectChain = null;
     this._stackBuilderSink  = null;
 }
Beispiel #3
0
        public static bool Disconnect(MarshalByRefObject obj)
        {
            if (obj == null)
            {
                throw new ArgumentNullException("obj");
            }

            ServerIdentity identity;

            if (IsTransparentProxy(obj))
            {
                // CBOs are always accessed through a proxy, even in the server, so
                // for server CBOs it is ok to disconnect a proxy

                RealProxy proxy = GetRealProxy(obj);
                if (proxy.GetProxiedType().IsContextful&& (proxy.ObjectIdentity is ServerIdentity))
                {
                    identity = proxy.ObjectIdentity as ServerIdentity;
                }
                else
                {
                    throw new ArgumentException("The obj parameter is a proxy.");
                }
            }
            else
            {
                identity           = obj.ObjectIdentity;
                obj.ObjectIdentity = null;
            }

            if (identity == null || !identity.IsConnected)
            {
                return(false);
            }
            else
            {
                LifetimeServices.StopTrackingLifetime(identity);
                DisposeIdentity(identity);
                TrackingServices.NotifyDisconnectedObject(obj);
                return(true);
            }
        }
Beispiel #4
0
        //   Creates a new server identity. This form is used by RemotingServices.Wrap
        //
        internal ServerIdentity(MarshalByRefObject obj, Context serverCtx) : base(obj is ContextBoundObject)
        {
            if (null != obj)
            {
                if (!RemotingServices.IsTransparentProxy(obj))
                {
                    _srvType = obj.GetType();
                }
                else
                {
                    RealProxy rp = RemotingServices.GetRealProxy(obj);
                    _srvType = rp.GetProxiedType();
                }
            }

            _srvCtx            = serverCtx;
            _serverObjectChain = null;
            _stackBuilderSink  = null;
            _refCount          = 0;
        }
Beispiel #5
0
        public static ObjRef Marshal(MarshalByRefObject Obj, string ObjURI, Type RequestedType)
        {
            if (IsTransparentProxy(Obj))
            {
                RealProxy proxy    = RemotingServices.GetRealProxy(Obj);
                Identity  identity = proxy.ObjectIdentity;

                if (identity != null)
                {
                    if (proxy.GetProxiedType().IsContextful&& !identity.IsConnected)
                    {
                        // Unregistered local contextbound object. Register now.
                        ClientActivatedIdentity cboundIdentity = (ClientActivatedIdentity)identity;
                        if (ObjURI == null)
                        {
                            ObjURI = NewUri();
                        }
                        cboundIdentity.ObjectUri = ObjURI;
                        RegisterServerIdentity(cboundIdentity);
                        cboundIdentity.StartTrackingLifetime((ILease)Obj.InitializeLifetimeService());
                        return(cboundIdentity.CreateObjRef(RequestedType));
                    }
                    else if (ObjURI != null)
                    {
                        throw new RemotingException("It is not possible marshal a proxy of a remote object.");
                    }

                    ObjRef or = proxy.ObjectIdentity.CreateObjRef(RequestedType);
                    TrackingServices.NotifyMarshaledObject(Obj, or);
                    return(or);
                }
            }

            if (RequestedType == null)
            {
                RequestedType = Obj.GetType();
            }

            if (ObjURI == null)
            {
                if (Obj.ObjectIdentity == null)
                {
                    ObjURI = NewUri();
                    CreateClientActivatedServerIdentity(Obj, RequestedType, ObjURI);
                }
            }
            else
            {
                ClientActivatedIdentity identity = GetIdentityForUri("/" + ObjURI) as ClientActivatedIdentity;
                if (identity == null || Obj != identity.GetServerObject())
                {
                    CreateClientActivatedServerIdentity(Obj, RequestedType, ObjURI);
                }
            }

            ObjRef oref;

            if (IsTransparentProxy(Obj))
            {
                oref = RemotingServices.GetRealProxy(Obj).ObjectIdentity.CreateObjRef(RequestedType);
            }
            else
            {
                oref = Obj.CreateObjRef(RequestedType);
            }

            TrackingServices.NotifyMarshaledObject(Obj, oref);
            return(oref);
        }