System.Runtime.Remoting.RemotingServices.SetObjectUriForMarshal C# (CSharp) Méthode

SetObjectUriForMarshal() private méthode

private SetObjectUriForMarshal ( MarshalByRefObject obj, String uri ) : void
obj MarshalByRefObject
uri String
Résultat void
        public static void SetObjectUriForMarshal( MarshalByRefObject obj, String uri)
        {
            // if obj is ever Marshal'd it should use this uri. If a uri has
            //   already been assigned to the object, it should throw.
            
            Message.DebugOut("Entered SetObjectUriForMarshal \n");
                    
            Identity idObj = null;
            Identity srvIdObj = null;
            
            bool fServer;
            idObj = MarshalByRefObject.GetIdentity(obj, out fServer);
            srvIdObj = idObj as ServerIdentity;
            
            // Ensure that if we have a transparent proxy then we are not given a remoting
            // proxy. This routine should only be called for objects that
            // live in this AppDomains.
            if ((idObj != null) && 
                (srvIdObj == null)) // <-- means idObj is not a ServerIdentity
            {
                throw new RemotingException(
                    Environment.GetResourceString(
                        "Remoting_SetObjectUriForMarshal__ObjectNeedsToBeLocal"));
            }


            if ((idObj != null) && (idObj.URI != null))
            {
                throw new RemotingException(
                    Environment.GetResourceString(
                        "Remoting_SetObjectUriForMarshal__UriExists"));
            }
            

            if (idObj == null)
            {
                // obj is not ContextBound
                BCLDebug.Assert(!(obj is ContextBoundObject), "ContextBoundObject's shouldn't get here.");
            
                // Create a new server identity and add it to the
                // table. IdentityHolder will take care of races
                Context serverCtx = null;
                
                serverCtx = Thread.GetDomain().GetDefaultContext();

                BCLDebug.Assert(null != serverCtx, "null != serverCtx");
    
                ServerIdentity serverID = new ServerIdentity(obj, serverCtx, uri);

                // set the identity 
                idObj = obj.__RaceSetServerIdentity(serverID);
                BCLDebug.Assert(idObj == MarshalByRefObject.GetIdentity(obj), "Bad ID state!" );                

                // If our serverID isn't used then someone else marshalled the object
                // before we could set the uri.
                if (idObj != serverID)
                {
                    throw new RemotingException(
                        Environment.GetResourceString(
                            "Remoting_SetObjectUriForMarshal__UriExists"));
                }
            }
            else
            {
                // This is the ContextBoundObject case
                BCLDebug.Assert(obj is ContextBoundObject, "Object should have been a ContextBoundObject.");

                idObj.SetOrCreateURI(uri, true);
            }

            Message.DebugOut("Created ServerIdentity \n");                        
        } // SetObjectUriForMarshal
RemotingServices