2 // System.Runtime.Remoting.Proxies.RemotingProxy.cs
5 // Dietmar Maurer (dietmar@ximian.com)
6 // Lluis Sanchez Gual (lsg@ctv.es)
8 // (C) 2001 Ximian, Inc. http://www.ximian.com
12 using System.Reflection;
13 using System.Runtime.Remoting.Messaging;
14 using System.Runtime.Remoting.Activation;
15 using System.Runtime.Remoting.Channels;
16 using System.Runtime.Remoting.Contexts;
17 using System.Runtime.CompilerServices;
18 using System.Threading;
21 namespace System.Runtime.Remoting.Proxies
24 public class RemotingProxy : RealProxy
26 static MethodInfo _cache_GetTypeMethod = typeof(System.Object).GetMethod("GetType");
\r
27 static MethodInfo _cache_GetHashCodeMethod = typeof(System.Object).GetMethod("GetHashCode");
\r
31 ConstructionCall _ctorCall;
33 internal RemotingProxy (Type type, ClientIdentity identity) : base (type, identity)
35 _sink = identity.ChannelSink;
36 _hasEnvoySink = false;
39 internal RemotingProxy (Type type, string activationUrl, object[] activationAttributes) : base (type)
41 _hasEnvoySink = false;
42 _ctorCall = ActivationServices.CreateConstructionCall (type, activationUrl, activationAttributes);
45 public override IMessage Invoke (IMessage request)
47 MonoMethodMessage mMsg = (MonoMethodMessage) request;
49 if (mMsg.MethodBase.IsConstructor)
50 return ActivateRemoteObject (mMsg);
52 if (mMsg.MethodBase == _cache_GetHashCodeMethod)
53 return new MethodResponse(ObjectIdentity.GetHashCode(), null, null, request as IMethodCallMessage);
\r
55 if (mMsg.MethodBase == _cache_GetTypeMethod)
56 return new MethodResponse(GetProxiedType(), null, null, request as IMethodCallMessage);
\r
58 mMsg.Uri = _objectIdentity.ObjectUri;
59 ((IInternalMessage)mMsg).TargetIdentity = _objectIdentity;
61 _objectIdentity.NotifyClientDynamicSinks (true, request, true, false);
65 // Needs to go through the client context sink?
66 if (Thread.CurrentContext.HasExitSinks && !_hasEnvoySink)
67 response = Thread.CurrentContext.GetClientContextSinkChain ().SyncProcessMessage (request);
69 response = _sink.SyncProcessMessage (request);
71 _objectIdentity.NotifyClientDynamicSinks (false, request, true, false);
76 internal void AttachIdentity (Identity identity)
78 _objectIdentity = identity;
80 if (identity is ClientActivatedIdentity) // It is a CBO
82 ClientActivatedIdentity cai = (ClientActivatedIdentity)identity;
83 _targetContext = cai.Context;
84 AttachServer (cai.GetServerObject ());
87 if (identity is ClientIdentity)
88 ((ClientIdentity)identity).ClientProxy = (MarshalByRefObject) GetTransparentProxy();
90 if (_objectIdentity.EnvoySink != null)
92 _sink = _objectIdentity.EnvoySink;
96 _sink = _objectIdentity.ChannelSink;
98 _ctorCall = null; // Object already constructed
101 IMessage ActivateRemoteObject (IMethodMessage request)
103 if (_ctorCall == null) // It must be a WKO
104 return new ReturnMessage (this, new object[0], 0, null, (IMethodCallMessage) request); // Ignore constructor call for WKOs
106 _ctorCall.CopyFrom (request);
107 return ActivationServices.Activate (this, _ctorCall);