private GetObjectUri ( |
||
obj | ||
리턴 | String |
internal IMessageSink GetServerObjectChain(out MarshalByRefObject obj) { obj = null; if (!this.IsSingleCall()) { if (this._serverObjectChain == null) { bool lockTaken = false; RuntimeHelpers.PrepareConstrainedRegions(); try { Monitor.Enter(this, ref lockTaken); if (this._serverObjectChain == null) { MarshalByRefObject tPOrObject = base.TPOrObject; this._serverObjectChain = this._srvCtx.CreateServerObjectChain(tPOrObject); } } finally { if (lockTaken) { Monitor.Exit(this); } } } return(this._serverObjectChain); } MarshalByRefObject serverObj = null; IMessageSink sink = null; if (((base._tpOrObject != null) && (this._firstCallDispatched == 0)) && (Interlocked.CompareExchange(ref this._firstCallDispatched, 1, 0) == 0)) { serverObj = (MarshalByRefObject)base._tpOrObject; sink = this._serverObjectChain; if (sink == null) { sink = this._srvCtx.CreateServerObjectChain(serverObj); } } else { serverObj = (MarshalByRefObject)Activator.CreateInstance(this._srvType, true); if (RemotingServices.GetObjectUri(serverObj) != null) { throw new RemotingException(string.Format(CultureInfo.CurrentCulture, Environment.GetResourceString("Remoting_WellKnown_CtorCantMarshal"), new object[] { base.URI })); } if (!RemotingServices.IsTransparentProxy(serverObj)) { serverObj.__RaceSetServerIdentity(this); } else { RemotingServices.GetRealProxy(serverObj).IdentityObject = this; } sink = this._srvCtx.CreateServerObjectChain(serverObj); } obj = serverObj; return(sink); }
public ObjRef(MarshalByRefObject o, Type requestedType) { if (o == null) { throw new ArgumentNullException("o"); } if (requestedType == null) { throw new ArgumentNullException("requestedType"); } // The ObjRef can only be constructed if the given o // has already been marshalled using RemotingServices.Marshall uri = RemotingServices.GetObjectUri(o); typeInfo = new TypeInfo(requestedType); if (!requestedType.IsInstanceOfType(o)) { throw new RemotingException("The server object type cannot be cast to the requested type " + requestedType.FullName); } UpdateChannelInfo(); }
/// <summary>Initializes a new instance of the <see cref="T:System.Runtime.Remoting.ObjRef" /> class to reference a specified <see cref="T:System.MarshalByRefObject" /> of a specified <see cref="T:System.Type" />.</summary> /// <param name="o">The object that the new <see cref="T:System.Runtime.Remoting.ObjRef" /> instance will reference. </param> /// <param name="requestedType">The <see cref="T:System.Type" /> of the object that the new <see cref="T:System.Runtime.Remoting.ObjRef" /> instance will reference. </param> public ObjRef(MarshalByRefObject o, Type requestedType) { if (o == null) { throw new ArgumentNullException("o"); } if (requestedType == null) { throw new ArgumentNullException("requestedType"); } this.uri = RemotingServices.GetObjectUri(o); this.typeInfo = new TypeInfo(requestedType); if (!requestedType.IsInstanceOfType(o)) { throw new RemotingException("The server object type cannot be cast to the requested type " + requestedType.FullName); } this.UpdateChannelInfo(); }
internal IMessageSink GetServerObjectChain(out MarshalByRefObject obj) { obj = null; // NOTE: Lifetime relies on the Identity flags for // SingleCall and Singleton being set by the time this getter // is called. // get // { if (!this.IsSingleCall()) { // This is the common case if (_serverObjectChain == null) { lock (this) { if (_serverObjectChain == null) { MarshalByRefObject srvObj = (MarshalByRefObject) this.TPOrObject; _serverObjectChain = _srvCtx.CreateServerObjectChain( srvObj); } } } BCLDebug.Assert(null != _serverObjectChain, "null != _serverObjectChain"); return(_serverObjectChain); } else { // ---------- SINGLE CALL WKO -------------- // In this case, we are expected to provide // a fresh server object for each dispatch. // Since the server object chain is object // specific, we must create a fresh chain too. // We must be in the correct context for this // to succeed. BCLDebug.Assert(Thread.CurrentContext == _srvCtx, "Bad context mismatch"); // For singleCall we create a fresh object & its chain // on each dispatch! MarshalByRefObject srvObj = (MarshalByRefObject) Activator.CreateInstance((Type)_srvType, true); // make sure that object didn't Marshal itself. // (well known objects should live up to their promise // of exporting themselves through exactly one url) String tempUri = RemotingServices.GetObjectUri(srvObj); if (tempUri != null) { throw new RemotingException( String.Format( Environment.GetResourceString( "Remoting_WellKnown_CtorCantMarshal"), this.URI)); } // Set the identity depending on whether we have the server // or proxy if (!RemotingServices.IsTransparentProxy(srvObj)) { #if _DEBUG Identity idObj = srvObj.__RaceSetServerIdentity(this); #else srvObj.__RaceSetServerIdentity(this); #endif #if _DEBUG BCLDebug.Assert(idObj == this, "Bad ID state!"); BCLDebug.Assert(idObj == MarshalByRefObject.GetIdentity(srvObj), "Bad ID state!"); #endif } else { RealProxy rp = null; rp = RemotingServices.GetRealProxy(srvObj); BCLDebug.Assert(null != rp, "null != rp"); // #if _DEBUG // Identity idObj = (ServerIdentity) rp.SetIdentity(this); // #else rp.IdentityObject = this; // #endif } // This is passed out to the caller so that for single-call // case we can call Dispose when the incoming call is done obj = srvObj; // Create the object chain and return it return(_srvCtx.CreateServerObjectChain(srvObj)); } // } }
internal IMessageSink GetServerObjectChain(out MarshalByRefObject obj) { obj = null; // NOTE: Lifetime relies on the Identity flags for // SingleCall and Singleton being set by the time this getter // is called. if (!this.IsSingleCall()) { // This is the common case if (_serverObjectChain == null) { lock (this) { if (_serverObjectChain == null) { MarshalByRefObject srvObj = (MarshalByRefObject) this.TPOrObject; _serverObjectChain = _srvCtx.CreateServerObjectChain( srvObj); } } } BCLDebug.Assert(null != _serverObjectChain, "null != _serverObjectChain"); return(_serverObjectChain); } else { // ---------- SINGLE CALL WKO -------------- // In this case, we are expected to provide // a fresh server object for each dispatch. // Since the server object chain is object // specific, we must create a fresh chain too. // We must be in the correct context for this // to succeed. // NOTE: It may be useful to recycle the context too // but for V1 we will keep the context we setup for // the first object around and always dispatch the call // through that context ... when we are here we have // already been through the server sink chain. We will // only dispatch through the object sink chain of the // object we will create below ... if for some reason // the object creates its own context we will not go // through the server sink chain for that context again. // We should fix this in V-next and always create everything // from scratch for single-call wellKnown objects BCLDebug.Assert(Thread.CurrentContext == _srvCtx, "Bad context mismatch"); MarshalByRefObject srvObj = null; IMessageSink objChain = null; if (_tpOrObject != null && _firstCallDispatched == 0 && Interlocked.CompareExchange(ref _firstCallDispatched, 1, 0) == 0) { // use the instance of server object created to // set up the pipeline. srvObj = (MarshalByRefObject)_tpOrObject; objChain = _serverObjectChain; if (objChain == null) { objChain = _srvCtx.CreateServerObjectChain(srvObj); } } else { // For singleCall we create a fresh object & its chain // on each dispatch! srvObj = (MarshalByRefObject) Activator.CreateInstance((Type)_srvType, true); // make sure that object didn't Marshal itself. // (well known objects should live up to their promise // of exporting themselves through exactly one url) String tempUri = RemotingServices.GetObjectUri(srvObj); if (tempUri != null) { throw new RemotingException( String.Format( Environment.GetResourceString( "Remoting_WellKnown_CtorCantMarshal"), this.URI)); } // Set the identity depending on whether we have the server // or proxy if (!RemotingServices.IsTransparentProxy(srvObj)) { #if _DEBUG Identity idObj = srvObj.__RaceSetServerIdentity(this); #else srvObj.__RaceSetServerIdentity(this); #endif #if _DEBUG BCLDebug.Assert(idObj == this, "Bad ID state!"); BCLDebug.Assert(idObj == MarshalByRefObject.GetIdentity(srvObj), "Bad ID state!"); #endif } else { RealProxy rp = null; rp = RemotingServices.GetRealProxy(srvObj); BCLDebug.Assert(null != rp, "null != rp"); // #if _DEBUG // Identity idObj = (ServerIdentity) rp.SetIdentity(this); // #else rp.IdentityObject = this; // #endif #if _DEBUG // REVIEW: turn these on after adding a clean way to // reset identity-s on x-context proxies ... (id needs // to be set in the proxy && on the _serverObject in // the proxy) // BCLDebug.Assert(idObj == this, "Bad ID state!" ); // BCLDebug.Assert(idObj == rp.IdentityObject, "Bad ID state!" ); #endif } // Create the object chain and return it objChain = _srvCtx.CreateServerObjectChain(srvObj); } // This is passed out to the caller so that for single-call // case we can call Dispose when the incoming call is done obj = srvObj; return(objChain); } }
internal IMessageSink GetServerObjectChain(out MarshalByRefObject obj) { obj = null; if (!this.IsSingleCall()) { if (this._serverObjectChain == null) { bool flag = false; RuntimeHelpers.PrepareConstrainedRegions(); try { Monitor.Enter(this, ref flag); if (this._serverObjectChain == null) { MarshalByRefObject tporObject = base.TPOrObject; this._serverObjectChain = this._srvCtx.CreateServerObjectChain(tporObject); } } finally { if (flag) { Monitor.Exit(this); } } } return(this._serverObjectChain); } MarshalByRefObject marshalByRefObject; IMessageSink messageSink; if (this._tpOrObject != null && this._firstCallDispatched == 0 && Interlocked.CompareExchange(ref this._firstCallDispatched, 1, 0) == 0) { marshalByRefObject = (MarshalByRefObject)this._tpOrObject; messageSink = this._serverObjectChain; if (messageSink == null) { messageSink = this._srvCtx.CreateServerObjectChain(marshalByRefObject); } } else { marshalByRefObject = (MarshalByRefObject)Activator.CreateInstance(this._srvType, true); string objectUri = RemotingServices.GetObjectUri(marshalByRefObject); if (objectUri != null) { throw new RemotingException(string.Format(CultureInfo.CurrentCulture, Environment.GetResourceString("Remoting_WellKnown_CtorCantMarshal"), base.URI)); } if (!RemotingServices.IsTransparentProxy(marshalByRefObject)) { marshalByRefObject.__RaceSetServerIdentity(this); } else { RealProxy realProxy = RemotingServices.GetRealProxy(marshalByRefObject); realProxy.IdentityObject = this; } messageSink = this._srvCtx.CreateServerObjectChain(marshalByRefObject); } obj = marshalByRefObject; return(messageSink); }
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); } }