System.Runtime.Remoting.ObjRef.GetServerContext C# (CSharp) Method

GetServerContext() private method

private GetServerContext ( int &domainId ) : IntPtr
domainId int
return System.IntPtr
        internal IntPtr GetServerContext(out int domainId)
        {
            IntPtr contextId = IntPtr.Zero;
            domainId = 0;
            if (IsFromThisProcess())
            {
                CrossAppDomainData xadData = GetAppDomainChannelData();
                BCLDebug.Assert(xadData != null, "bad objRef?");
                domainId = xadData.DomainID;
                if (AppDomain.IsDomainIdValid(xadData.DomainID))
                {
                    contextId = xadData.ContextID;
                }
            }
            return contextId;
        }

Usage Example

示例#1
0
        [System.Security.SecurityCritical]  // auto-generated 
        private static IntPtr GetServerContextForProxy( 
            Object tp, out ObjRef objRef, out bool bSameDomain, out int domainId)
        { 
            // Note: the contextId we return from here should be the address
            // of the unmanaged (VM) context object or NULL.

            IntPtr contextId = IntPtr.Zero; 
            objRef = null;
            bSameDomain = false; 
            domainId = 0; 
            if (IsTransparentProxy(tp))
            { 
                // This is a transparent proxy. Try to obtain the backing
                // RealProxy from it.
                RealProxy rp = GetRealProxy(tp);
 
                // Get the identity from the realproxy
                Identity id = rp.IdentityObject; 
                if(null != id) 
                {
                    ServerIdentity serverID = id as ServerIdentity; 
                    if (null != serverID)
                    {
                        // We are in the app domain of the server
                        bSameDomain = true; 
                        contextId = serverID.ServerContext.InternalContextID;
                        domainId = Thread.GetDomain().GetId(); 
                    } 
                    else
                    { 
                        // Server is from another app domain
                        // (possibly from another process)
                        objRef = id.ObjectRef;
                        if (objRef != null) 
                        {
                            contextId = objRef.GetServerContext(out domainId); 
                        } 
                        else
                        { 
                            // Proxy does not have an associated ObjRef
                            // <

 

                            //Contract.Assert(false, "Found proxy without an objref"); 
                            contextId = IntPtr.Zero; 
                        }
                    } 
                }
                else
                {
                    // This was probably a custom proxy other than RemotingProxy 
                    Contract.Assert(
                        !(rp is RemotingProxy), 
                        "!(rp is RemotingProxy)"); 

                    contextId = Context.DefaultContext.InternalContextID; 
                }
            }

            return contextId; 
        }
All Usage Examples Of System.Runtime.Remoting.ObjRef::GetServerContext