// Set this object's identity.
	internal void SetIdentity(RemotingServices.Identity identity)
			{
				lock(this)
				{
					if(RemotingServices.IsTransparentProxy(this))
					{
						RemotingServices.GetRealProxy(this).Identity
							= identity;
					}
					else
					{
						this.identity = identity;
					}
				}
			}
Exemple #2
0
 public static void RegisterWellKnownClientType(WellKnownClientTypeEntry entry)
 {
     RemotingConfigHandler.RegisterWellKnownClientType(entry);
     RemotingServices.InternalSetRemoteActivationConfigured();
 }
Exemple #3
0
 public static void Configure(string filename, bool ensureSecurity)
 {
     RemotingConfigHandler.DoConfiguration(filename, ensureSecurity);
     RemotingServices.InternalSetRemoteActivationConfigured();
 }
        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);
        }
Exemple #5
0
        //
        //
        internal void Init(Identity idObj, Type requestedType)
        {
            Message.DebugOut("RemotingServices::FillObjRef: IN");
            BCLDebug.Assert(idObj != null, "idObj != null");

            // Set the URI of the object to be marshaled
            URI = idObj.URI;

            // Figure out the type
            MarshalByRefObject obj = idObj.TPOrObject;

            BCLDebug.Assert(null != obj, "Identity not setup correctly");

            // Get the type of the object
            Type serverType = null;

            if (!RemotingServices.IsTransparentProxy(obj))
            {
                serverType = obj.GetType();
            }
            else
            {
                serverType = RemotingServices.GetRealProxy(obj).GetProxiedType();
            }

            Type typeOfObj = (null == requestedType ? serverType : requestedType);

            // Make sure that the server and requested types are compatible
            //  (except for objects that implement IMessageSink, since we
            //   just hand off the message instead of invoking the proxy)
            if ((null != requestedType) &&
                !requestedType.IsAssignableFrom(serverType) &&
                (!typeof(IMessageSink).IsAssignableFrom(serverType)))
            {
                throw new RemotingException(
                          String.Format(
                              Environment.GetResourceString(
                                  "Remoting_InvalidRequestedType"),
                              requestedType.ToString()));;
            }

            // Create the type info
            if (serverType.IsCOMObject)
            {
                // __ComObjects need dynamic TypeInfo
                DynamicTypeInfo dt = new DynamicTypeInfo(typeOfObj);
                TypeInfo = (IRemotingTypeInfo)dt;
            }
            else
            {
                RemotingTypeCachedData cache = (RemotingTypeCachedData)
                                               InternalRemotingServices.GetReflectionCachedData(typeOfObj);

                TypeInfo = (IRemotingTypeInfo)cache.TypeInfo;
            }

            if (!idObj.IsWellKnown())
            {
                // Create the envoy info
                EnvoyInfo = System.Runtime.Remoting.EnvoyInfo.CreateEnvoyInfo(idObj as ServerIdentity);

                // Create the channel info
                ChannelInfo = (IChannelInfo) new ChannelInfo();

                if (serverType.HasProxyAttribute)
                {
                    SetHasProxyAttribute();
                }
            }
            else
            {
                SetWellKnown();
            }

            // See if we should and can use a url obj ref?
            if (ShouldUseUrlObjRef())
            {
                if (IsWellKnown())
                {
                    // full uri already supplied.
                    SetObjRefLite();
                }
                else
                {
                    String httpUri = ChannelServices.FindFirstHttpUrlForObject(URI);
                    if (httpUri != null)
                    {
                        URI = httpUri;
                        SetObjRefLite();
                    }
                }
            }
        } // Init
Exemple #6
0
        private bool CompareTypes(Type type1, String type2)
        {
            Type type = RemotingServices.InternalGetTypeFromQualifiedTypeName(type2);

            return(type1 == type);
        }
Exemple #7
0
        internal void Init(object o, Identity idObj, RuntimeType requestedType)
        {
            this.uri = idObj.URI;
            MarshalByRefObject tPOrObject = idObj.TPOrObject;
            RuntimeType        c          = null;

            if (!RemotingServices.IsTransparentProxy(tPOrObject))
            {
                c = (RuntimeType)tPOrObject.GetType();
            }
            else
            {
                c = (RuntimeType)RemotingServices.GetRealProxy(tPOrObject).GetProxiedType();
            }
            RuntimeType typeOfObj = (null == requestedType) ? c : requestedType;

            if (((null != requestedType) && !requestedType.IsAssignableFrom(c)) && !typeof(IMessageSink).IsAssignableFrom(c))
            {
                throw new RemotingException(string.Format(CultureInfo.CurrentCulture, Environment.GetResourceString("Remoting_InvalidRequestedType"), new object[] { requestedType.ToString() }));
            }
            if (c.IsCOMObject)
            {
                DynamicTypeInfo info = new DynamicTypeInfo(typeOfObj);
                this.TypeInfo = info;
            }
            else
            {
                RemotingTypeCachedData reflectionCachedData = InternalRemotingServices.GetReflectionCachedData(typeOfObj);
                this.TypeInfo = reflectionCachedData.TypeInfo;
            }
            if (!idObj.IsWellKnown())
            {
                this.EnvoyInfo = System.Runtime.Remoting.EnvoyInfo.CreateEnvoyInfo(idObj as ServerIdentity);
                IChannelInfo info2 = new System.Runtime.Remoting.ChannelInfo();
                if (o is AppDomain)
                {
                    object[] channelData      = info2.ChannelData;
                    int      length           = channelData.Length;
                    object[] destinationArray = new object[length];
                    Array.Copy(channelData, destinationArray, length);
                    for (int i = 0; i < length; i++)
                    {
                        if (!(destinationArray[i] is CrossAppDomainData))
                        {
                            destinationArray[i] = null;
                        }
                    }
                    info2.ChannelData = destinationArray;
                }
                this.ChannelInfo = info2;
                if (c.HasProxyAttribute)
                {
                    this.SetHasProxyAttribute();
                }
            }
            else
            {
                this.SetWellKnown();
            }
            if (ShouldUseUrlObjRef())
            {
                if (this.IsWellKnown())
                {
                    this.SetObjRefLite();
                }
                else
                {
                    string str = ChannelServices.FindFirstHttpUrlForObject(this.URI);
                    if (str != null)
                    {
                        this.URI = str;
                        this.SetObjRefLite();
                    }
                }
            }
        }
        internal static ServerIdentity FindOrCreateServerIdentity(MarshalByRefObject obj, string objURI, int flags)
        {
            ServerIdentity serverIdentity = null;
            bool           flag;

            serverIdentity = (ServerIdentity)MarshalByRefObject.GetIdentity(obj, out flag);
            if (serverIdentity == null)
            {
                Context serverCtx;
                if (obj is ContextBoundObject)
                {
                    serverCtx = Thread.CurrentContext;
                }
                else
                {
                    serverCtx = IdentityHolder.DefaultContext;
                }
                ServerIdentity serverIdentity2 = new ServerIdentity(obj, serverCtx);
                if (flag)
                {
                    serverIdentity = obj.__RaceSetServerIdentity(serverIdentity2);
                }
                else
                {
                    RealProxy realProxy = RemotingServices.GetRealProxy(obj);
                    realProxy.IdentityObject = serverIdentity2;
                    serverIdentity           = (ServerIdentity)realProxy.IdentityObject;
                }
                if (IdOps.bIsInitializing(flags))
                {
                    serverIdentity.IsInitializing = true;
                }
            }
            if (IdOps.bStrongIdentity(flags))
            {
                ReaderWriterLock tableLock = IdentityHolder.TableLock;
                bool             flag2     = !tableLock.IsWriterLockHeld;
                RuntimeHelpers.PrepareConstrainedRegions();
                try
                {
                    if (flag2)
                    {
                        tableLock.AcquireWriterLock(int.MaxValue);
                    }
                    if (serverIdentity.ObjURI == null || !serverIdentity.IsInIDTable())
                    {
                        IdentityHolder.SetIdentity(serverIdentity, objURI, DuplicateIdentityOption.Unique);
                    }
                    if (serverIdentity.IsDisconnected())
                    {
                        serverIdentity.SetFullyConnected();
                    }
                }
                finally
                {
                    if (flag2 && tableLock.IsWriterLockHeld)
                    {
                        tableLock.ReleaseWriterLock();
                    }
                }
            }
            return(serverIdentity);
        }
        /// <summary>Returns a Boolean value that indicates whether the current <see cref="T:System.Runtime.Remoting.ObjRef" /> instance references an object located in the current <see cref="T:System.AppDomain" />.</summary>
        /// <returns>A Boolean value that indicates whether the current <see cref="T:System.Runtime.Remoting.ObjRef" /> instance references an object located in the current <see cref="T:System.AppDomain" />.</returns>
        /// <PermissionSet>
        ///   <IPermission class="System.Security.Permissions.SecurityPermission, mscorlib, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Flags="Infrastructure" />
        /// </PermissionSet>
        public bool IsFromThisAppDomain()
        {
            Identity identityForUri = RemotingServices.GetIdentityForUri(this.uri);

            return(identityForUri != null && identityForUri.IsFromThisAppDomain);
        }
 internal ServerIdentity StartupWellKnownObject(string asmName, string svrTypeName, string URI, WellKnownObjectMode mode, bool fReplace)
 {
     lock (s_wkoStartLock)
     {
         MarshalByRefObject obj2     = null;
         ServerIdentity     identity = null;
         Type type = LoadType(svrTypeName, asmName);
         if (!type.IsMarshalByRef)
         {
             throw new RemotingException(Environment.GetResourceString("Remoting_WellKnown_MustBeMBR", new object[] { svrTypeName }));
         }
         identity = (ServerIdentity)IdentityHolder.ResolveIdentity(URI);
         if ((identity != null) && identity.IsRemoteDisconnected())
         {
             IdentityHolder.RemoveIdentity(URI);
             identity = null;
         }
         if (identity == null)
         {
             s_fullTrust.Assert();
             try
             {
                 obj2 = (MarshalByRefObject)Activator.CreateInstance(type, true);
                 if (RemotingServices.IsClientProxy(obj2))
                 {
                     RedirectionProxy proxy = new RedirectionProxy(obj2, type)
                     {
                         ObjectMode = mode
                     };
                     RemotingServices.MarshalInternal(proxy, URI, type);
                     identity = (ServerIdentity)IdentityHolder.ResolveIdentity(URI);
                     identity.SetSingletonObjectMode();
                 }
                 else if (type.IsCOMObject && (mode == WellKnownObjectMode.Singleton))
                 {
                     ComRedirectionProxy proxy2 = new ComRedirectionProxy(obj2, type);
                     RemotingServices.MarshalInternal(proxy2, URI, type);
                     identity = (ServerIdentity)IdentityHolder.ResolveIdentity(URI);
                     identity.SetSingletonObjectMode();
                 }
                 else
                 {
                     if (RemotingServices.GetObjectUri(obj2) != null)
                     {
                         throw new RemotingException(string.Format(CultureInfo.CurrentCulture, Environment.GetResourceString("Remoting_WellKnown_CtorCantMarshal"), new object[] { URI }));
                     }
                     RemotingServices.MarshalInternal(obj2, URI, type);
                     identity = (ServerIdentity)IdentityHolder.ResolveIdentity(URI);
                     if (mode == WellKnownObjectMode.SingleCall)
                     {
                         identity.SetSingleCallObjectMode();
                     }
                     else
                     {
                         identity.SetSingletonObjectMode();
                     }
                 }
             }
             catch
             {
                 throw;
             }
             finally
             {
                 CodeAccessPermission.RevertAssert();
             }
         }
         return(identity);
     }
 }
Exemple #11
0
        [System.Security.SecurityCritical]  // auto-generated
        internal void Init(Object o, Identity idObj, RuntimeType requestedType)
        {
            Message.DebugOut("RemotingServices::FillObjRef: IN");
            BCLDebug.Assert(idObj != null, "idObj != null");

            // Set the URI of the object to be marshaled
            uri = idObj.URI;

            // Figure out the type
            MarshalByRefObject obj = idObj.TPOrObject;

            BCLDebug.Assert(null != obj, "Identity not setup correctly");

            // Get the type of the object
            RuntimeType serverType = null;

            if (!RemotingServices.IsTransparentProxy(obj))
            {
                serverType = (RuntimeType)obj.GetType();
            }
            else
            {
                serverType = (RuntimeType)RemotingServices.GetRealProxy(obj).GetProxiedType();
            }

            RuntimeType typeOfObj = (null == requestedType ? serverType : requestedType);

            // Make sure that the server and requested types are compatible
            //  (except for objects that implement IMessageSink, since we
            //   just hand off the message instead of invoking the proxy)
            if ((null != requestedType) &&
                !requestedType.IsAssignableFrom(serverType) &&
                (!typeof(IMessageSink).IsAssignableFrom(serverType)))
            {
                throw new RemotingException(
                          String.Format(
                              CultureInfo.CurrentCulture, Environment.GetResourceString(
                                  "Remoting_InvalidRequestedType"),
                              requestedType.ToString()));;
            }

            // Create the type info
            if (serverType.IsCOMObject)
            {
                // __ComObjects need dynamic TypeInfo
                DynamicTypeInfo dt = new DynamicTypeInfo(typeOfObj);
                TypeInfo = (IRemotingTypeInfo)dt;
            }
            else
            {
                RemotingTypeCachedData cache = (RemotingTypeCachedData)
                                               InternalRemotingServices.GetReflectionCachedData(typeOfObj);

                TypeInfo = (IRemotingTypeInfo)cache.TypeInfo;
            }

            if (!idObj.IsWellKnown())
            {
                // Create the envoy info
                EnvoyInfo = System.Runtime.Remoting.EnvoyInfo.CreateEnvoyInfo(idObj as ServerIdentity);

                // Create the channel info
                IChannelInfo chan = (IChannelInfo) new ChannelInfo();
                // Make sure the channelInfo only has x-appdomain data since the objref is agile while other
                // channelData might not be and regardless this data is useless for an appdomain proxy
                if (o is AppDomain)
                {
                    Object[] channelData       = chan.ChannelData;
                    int      channelDataLength = channelData.Length;
                    Object[] newChannelData    = new Object[channelDataLength];
                    // Clone the data so that we dont [....] the current appdomain data which is stored
                    // as a static
                    Array.Copy(channelData, newChannelData, channelDataLength);
                    for (int i = 0; i < channelDataLength; i++)
                    {
                        if (!(newChannelData[i] is CrossAppDomainData))
                        {
                            newChannelData[i] = null;
                        }
                    }
                    chan.ChannelData = newChannelData;
                }
                ChannelInfo = chan;

                if (serverType.HasProxyAttribute)
                {
                    SetHasProxyAttribute();
                }
            }
            else
            {
                SetWellKnown();
            }

            // See if we should and can use a url obj ref?
            if (ShouldUseUrlObjRef())
            {
                if (IsWellKnown())
                {
                    // full uri already supplied.
                    SetObjRefLite();
                }
                else
                {
                    String httpUri = ChannelServices.FindFirstHttpUrlForObject(URI);
                    if (httpUri != null)
                    {
                        URI = httpUri;
                        SetObjRefLite();
                    }
                }
            }
        } // Init
Exemple #12
0
        internal static bool RemoveDynamicProperty(MarshalByRefObject obj, string name)
        {
            if (RemotingServices.IsObjectOutOfContext((object)obj))
            {
                return(RemotingServices.GetRealProxy((object)obj).IdentityObject.RemoveProxySideDynamicProperty(name));
            }
            ServerIdentity serverIdentity = (ServerIdentity)MarshalByRefObject.GetIdentity((MarshalByRefObject)RemotingServices.AlwaysUnwrap((ContextBoundObject)obj));

            if (serverIdentity != null)
            {
                return(serverIdentity.RemoveServerSideDynamicProperty(name));
            }
            throw new RemotingException(Environment.GetResourceString("Remoting_NoIdentityEntry"));
        }