protected RealProxy(Type classToProxy, IntPtr stub, Object stubData) { // The class must be either an interface or MarshalByRef. if(!(classToProxy.IsInterface) && !(classToProxy.IsMarshalByRef)) { throw new ArgumentException (_("Remoting_NotMarshalOrInterface"), "classToProxy"); } // Get the default stub data if necessary. if(stub == IntPtr.Zero) { stubData = defaultStub; } // Validate the stub data. if(stubData == null) { throw new ArgumentNullException("stubData"); } // Initialize this object's state. this.type = classToProxy; this.stubData = stubData; this.serverObject = null; this.proxy = CreateTransparentProxy(classToProxy); }
public MyProxy(MarshalByRefObject target) : base(target.GetType()) { this.target = target; }
// Get a lifetime service object. public static Object GetLifetimeService(MarshalByRefObject obj) { if(obj == null) { return null; } return obj.GetLifetimeService(); }
// Get the envoy chain for a specific proxy object. public static IMessageSink GetEnvoyChainForProxy (MarshalByRefObject obj) { if(IsObjectOutOfContext(obj)) { RealProxy proxy = GetRealProxy(obj); Identity id = proxy.Identity; if(id != null) { return id.envoyChain; } } return null; }
// Register an object for sponsorship. public bool Register(MarshalByRefObject obj) { // If there is no lease on the object, then bail out. ILease lease = (ILease)(obj.GetLifetimeService()); if(lease == null) { return false; } // Inform the lease about the registered sponsor. lease.Register(this); // Add the lease to the sponsor table. lock(this) { sponsoredObjects[obj] = lease; } return true; }
// Get the default lifetime service object for a marshal-by-ref object. internal static Object GetLifetimeService(MarshalByRefObject obj) { return GetLifetimeManager().GetLeaseForObject(obj); }
// Get an active lease for an object. public ILease GetLeaseForObject(MarshalByRefObject obj) { // TODO return null; }
internal static Identity GetObjectIdentity (MarshalByRefObject obj) { if (IsTransparentProxy(obj)) return GetRealProxy (obj).ObjectIdentity; else return obj.ObjectIdentity; }
// Unregister an object from the sponsorship list. public void Unregister(MarshalByRefObject obj) { ILease lease; lock(this) { lease = (ILease)(sponsoredObjects[obj]); if(lease == null) { return; } sponsoredObjects.Remove(obj); } lease.Unregister(this); }
public static bool Disconnect (MarshalByRefObject obj) { if (obj == null) throw new ArgumentNullException ("obj"); ServerIdentity identity; if (IsTransparentProxy (obj)) { // CBOs are always accessed through a proxy, even in the server, so // for server CBOs it is ok to disconnect a proxy RealProxy proxy = GetRealProxy(obj); if (proxy.GetProxiedType().IsContextful && (proxy.ObjectIdentity is ServerIdentity)) identity = proxy.ObjectIdentity as ServerIdentity; else throw new ArgumentException ("The obj parameter is a proxy."); } else { identity = obj.ObjectIdentity; obj.ObjectIdentity = null; } if (identity == null || !identity.IsConnected) return false; else { LifetimeServices.StopTrackingLifetime (identity); DisposeIdentity (identity); TrackingServices.NotifyDisconnectedObject (obj); return true; } }
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; }
public IMessageSink GetObjectSink(MarshalByRefObject obj, IMessageSink nextSink) { bool flag; ServerIdentity identity = (ServerIdentity)MarshalByRefObject.GetIdentity(obj, out flag); if (!identity.IsSingleCall()) { object obj2 = obj.InitializeLifetimeService(); if (obj2 == null) { return(nextSink); } if (!(obj2 is ILease)) { throw new RemotingException(Environment.GetResourceString("Remoting_Lifetime_ILeaseReturn", new object[] { obj2 })); } ILease lease = (ILease)obj2; if (lease.InitialLeaseTime.CompareTo(TimeSpan.Zero) <= 0) { if (lease is Lease) { ((Lease)lease).Remove(); } return(nextSink); } Lease leaseInitial = null; lock (identity) { if (identity.Lease != null) { leaseInitial = identity.Lease; leaseInitial.Renew(leaseInitial.InitialLeaseTime); } else { if (lease is Lease) { leaseInitial = (Lease)lease; } else { leaseInitial = (Lease)LifetimeServices.GetLeaseInitial(obj); if (leaseInitial.CurrentState == LeaseState.Initial) { leaseInitial.InitialLeaseTime = lease.InitialLeaseTime; leaseInitial.RenewOnCallTime = lease.RenewOnCallTime; leaseInitial.SponsorshipTimeout = lease.SponsorshipTimeout; } } identity.Lease = leaseInitial; if (identity.ObjectRef != null) { leaseInitial.ActivateLease(); } } } if (leaseInitial.RenewOnCallTime > TimeSpan.Zero) { return(new LeaseSink(leaseInitial, nextSink)); } } return(nextSink); }
// Detach this proxy from a remote server. protected MarshalByRefObject DetachServer() { MarshalByRefObject saved = serverObject; serverObject = null; return saved; }
//+=========================================================== // // Method: Constructor, public // // Synopsis: Store server object // // History: 06-May-1999 <EMAIL>MattSmit</EMAIL> Created //-=========================================================== public StackBuilderSink(MarshalByRefObject server) { _server = server; }
[System.Security.SecurityCritical] // auto-generated private static void VerifyIsOkToCallMethod(Object server, IMethodMessage msg) { bool bTypeChecked = false; MarshalByRefObject mbr = server as MarshalByRefObject; if (mbr != null) { bool fServer; Identity id = MarshalByRefObject.GetIdentity(mbr, out fServer); if (id != null) { ServerIdentity srvId = id as ServerIdentity; if ((srvId != null) && srvId.MarshaledAsSpecificType) { Type srvType = srvId.ServerType; if (srvType != null) { MethodBase mb = GetMethodBase(msg); RuntimeType declaringType = (RuntimeType)mb.DeclaringType; // make sure that srvType is not more restrictive than method base // (i.e. someone marshaled with a specific type or interface exposed) if ((declaringType != srvType) && !declaringType.IsAssignableFrom(srvType)) { throw new RemotingException( String.Format( CultureInfo.CurrentCulture, Environment.GetResourceString("Remoting_InvalidCallingType"), mb.DeclaringType.FullName, srvType.FullName)); } // Set flag so we don't repeat this work below. if (declaringType.IsInterface) { VerifyNotIRemoteDispatch(declaringType); } bTypeChecked = true; } } } // We must always verify that the type corresponding to // the method being invoked is compatible with the real server // type. if (!bTypeChecked) { MethodBase mb = GetMethodBase(msg); RuntimeType reflectedType = (RuntimeType)mb.ReflectedType; if (!reflectedType.IsInterface) { if (!reflectedType.IsInstanceOfType(mbr)) { throw new RemotingException( String.Format( CultureInfo.CurrentCulture, Environment.GetResourceString("Remoting_InvalidCallingType"), reflectedType.FullName, mbr.GetType().FullName)); } } // This code prohibits calls made to System.EnterpriseServices.IRemoteDispatch // so that remote call cannot bypass lowFilterLevel logic in the serializers. // This special casing should be removed in the future else { VerifyNotIRemoteDispatch(reflectedType); } } } } // VerifyIsOkToCallMethod
// Create a return message for a constructor call. public static IConstructionReturnMessage CreateConstructionReturnMessage (IConstructionCallMessage ctorMsg, MarshalByRefObject retObj) { // Not used in this implementation. return(null); }
/// <summary> /// 将所提供的服务器对象的消息接收器连接到给定的接收器链前面。 /// </summary> /// <param name="obj">提供要连接到给定的接收器链前面的消息接收器的服务器对象。 </param> /// <param name="next">到目前为止组成的接收链。</param> /// <returns>复合接收器链。</returns> public IMessageSink GetObjectSink(MarshalByRefObject obj, IMessageSink next) { return(new KibaMessageSink(next)); }
IMessageSink IContributeEnvoySink.GetEnvoySink(MarshalByRefObject obj, IMessageSink nextSink) { CallSeq.Add("IContributeEnvoySink(" + id + ").GetEnvoySink"); return(new GenericMessageSink(obj, nextSink, "EnvoySink(" + id + ")")); }
public AopProxy(Type serverType, MarshalByRefObject target) : base(serverType) { _target = target; method = serverType.GetMethod("Set", BindingFlags.NonPublic | BindingFlags.Instance); }
internal static IMessage ExecuteMessage(MarshalByRefObject target, IMethodCallMessage callMsg) { throw new NotImplementedException(); }
public IConstructionReturnMessage InitializeServerObject (IConstructionCallMessage ctorMsg) { // Nothing to do if we already have a server object. if(serverObject != null) { return null; } // Create the server object. Type serverType = GetProxiedType(); if(ctorMsg != null && ctorMsg.ActivationType != serverType) { throw new RemotingException(_("Remoting_CtorMsg")); } serverObject = (MarshalByRefObject) FormatterServices.GetUninitializedObject(serverType); if(stubData == defaultStub) { stubData = Thread.CurrentContext.ContextID; } Object proxy = GetTransparentProxy(); if(ctorMsg == null) { // TODO: create a default constructor call message. } IMethodReturnMessage returnMessage; returnMessage = RemotingServices.ExecuteMessage ((MarshalByRefObject)proxy, ctorMsg); return new ConstructionResponse(returnMessage); }
internal static RealProxy GetRealProxy(MarshalByRefObject target) { throw new NotImplementedException(); }
internal static IMethodReturnMessage InternalExecuteMessage ( MarshalByRefObject target, IMethodCallMessage reqMsg) { ReturnMessage result; Type tt = target.GetType (); MethodBase method; if (reqMsg.MethodBase.DeclaringType == tt || reqMsg.MethodBase == FieldSetterMethod || reqMsg.MethodBase == FieldGetterMethod) { method = reqMsg.MethodBase; } else { method = GetVirtualMethod (tt, reqMsg.MethodBase); if (method == null) throw new RemotingException ( String.Format ("Cannot resolve method {0}:{1}", tt, reqMsg.MethodName)); } if (reqMsg.MethodBase.IsGenericMethod) { Type[] genericArguments = reqMsg.MethodBase.GetGenericArguments (); MethodInfo gmd = ((MethodInfo)method).GetGenericMethodDefinition (); method = gmd.MakeGenericMethod (genericArguments); } object oldContext = CallContext.SetCurrentCallContext (reqMsg.LogicalCallContext); try { object [] out_args; object rval = InternalExecute (method, target, reqMsg.Args, out out_args); // Collect parameters with Out flag from the request message // FIXME: This can be done in the unmanaged side and will be // more efficient ParameterInfo[] parameters = method.GetParameters(); object[] returnArgs = new object [parameters.Length]; int n = 0; int noa = 0; foreach (ParameterInfo par in parameters) { if (par.IsOut && !par.ParameterType.IsByRef) returnArgs [n++] = reqMsg.GetArg (par.Position); else if (par.ParameterType.IsByRef) returnArgs [n++] = out_args [noa++]; else returnArgs [n++] = null; } result = new ReturnMessage (rval, returnArgs, n, CallContext.CreateLogicalCallContext (true), reqMsg); } catch (Exception e) { result = new ReturnMessage (e, reqMsg); } CallContext.RestoreCallContext (oldContext); return result; }
public DynamicProxy(MarshalByRefObject decorated, Type serverType) : base(serverType) { _decorated = decorated; Filter = m => true; }
public static ObjRef Marshal (MarshalByRefObject Obj) { return Marshal (Obj, null, null); }
/// <summary> /// 创建Aop代理基类 /// </summary> /// <param name="obj">被代理对象</param> public AopProxyBase(MarshalByRefObject obj) : base(obj.GetType()) { this.target = obj; }
public static IMessageSink GetEnvoyChainForProxy (MarshalByRefObject obj) { if (IsTransparentProxy(obj)) return ((ClientIdentity)GetRealProxy (obj).ObjectIdentity).EnvoySink; else throw new ArgumentException ("obj must be a proxy.","obj"); }
/// <summary> /// 代理调用方法 /// </summary> /// <param name="msg">方法信息</param> /// <returns></returns> public override IMessage Invoke(IMessage msg) { IMethodCallMessage call = (IMethodCallMessage)msg; #region 检索AOP特性标记 AopMethodConfigAttribute methodAopAttr = null; var attrs = call.MethodBase.GetCustomAttributes(typeof(AopMethodConfigAttribute), false); if (attrs.Length > 0) { methodAopAttr = attrs[0] as AopMethodConfigAttribute; } #endregion #region 方法执行前拦截 if (methodAopAttr != null) { var provider = GetOperatorProvider(methodAopAttr.InvokingProvider); if (provider != null) { provider.Invoking(msg); } if (methodAopAttr.UseDefaultBeginAop) { this.Invoking(msg); } } #endregion #region 执行方法 IMethodReturnMessage returnMsg = null; //如果触发的是构造函数,此时target的构建还未开始 IConstructionCallMessage ctor = call as IConstructionCallMessage; if (ctor != null) { //获取最底层的默认真实代理 RealProxy default_proxy = RemotingServices.GetRealProxy(this.target); default_proxy.InitializeServerObject(ctor); MarshalByRefObject tp = (MarshalByRefObject)this.GetTransparentProxy(); //自定义的透明代理 this return(EnterpriseServicesHelper.CreateConstructionReturnMessage(ctor, tp)); } else { returnMsg = RemotingServices.ExecuteMessage(this.target, call); //将消息转化为堆栈,并执行目标方法,方法完成后,再将堆栈转化为消息 } #endregion #region 异常处理 if (returnMsg.Exception != null) { IAopOperator provider = null; if (methodAopAttr != null) { provider = GetOperatorProvider(methodAopAttr.OnExceptionProvider); } if (provider != null) { provider.OnException(msg, returnMsg.Exception); } else if ((target as IException) != null) { ((IException)target).OnException(msg, returnMsg.Exception); } else { this.OnException(msg, returnMsg.Exception); } object value = null; var methodInfo = (System.Reflection.MethodInfo)returnMsg.MethodBase; if (methodInfo.ReturnType != typeof(void) && methodAopAttr != null && methodAopAttr.ReturnExceptionDefaultValue) { value = Activator.CreateInstance(methodInfo.ReturnType, methodAopAttr.ExceptionDefaultValue); } returnMsg = new ReturnMessage(value, returnMsg.OutArgs, returnMsg.OutArgCount, returnMsg.LogicalCallContext, call); } #endregion #region 方法执行后拦截 else if (methodAopAttr != null) { var provider = GetOperatorProvider(methodAopAttr.InvokedProvider); if (provider != null) { provider.Invoked(msg, returnMsg); } if (methodAopAttr.UseDefaultEndAop) { this.Invoked(msg, returnMsg); } } #endregion return(returnMsg); }
public static IConstructionReturnMessage CreateConstructionReturnMessage (IConstructionCallMessage ctorMsg, MarshalByRefObject retObj) { return new ConstructionResponse (retObj, null, ctorMsg); }
protected void AttachServer(MarshalByRefObject s) { _server = s; }
IMessageSink IContributeObjectSink.GetObjectSink(MarshalByRefObject o, IMessageSink next) { CallSeq.Add("IContributeObjectSink(" + id + ").GetObjectSink"); return(new GenericMessageSink(o, next, "ObjectSink(" + id + ")")); }
public bool CanCastTo(Type castType, Object o) { if (castType == null) { throw new ArgumentNullException("castType"); } RuntimeType rtType = castType as RuntimeType; if (rtType == null) { throw new ArgumentException(Environment.GetResourceString("Argument_MustBeRuntimeType")); } bool fCastOK = false; // The identity should be non-null BCLDebug.Assert(null != IdentityObject, "null != IdentityObject"); Message.DebugOut("CheckCast for identity " + IdentityObject.GetType()); if ((rtType == s_typeofObject) || (rtType == s_typeofMarshalByRefObject)) { return(true); } // Get the objref of the proxy ObjRef oRef = IdentityObject.ObjectRef; // If the object ref is non-null then check against the type info // stored in the it if (null != oRef) { Object oTP = GetTransparentProxy(); // Check that there is a matching type in the server object // hierarchy represented in the objref Message.DebugOut("Calling CanCastTo for type " + rtType); IRemotingTypeInfo typeInfo = oRef.TypeInfo; if (null != typeInfo) { fCastOK = typeInfo.CanCastTo(rtType, oTP); if (!fCastOK && typeInfo.GetType() == typeof(TypeInfo) && oRef.IsWellKnown()) { fCastOK = CanCastToWK(rtType); } } else { if (oRef.IsObjRefLite()) { // we should do a dynamic cast across the network fCastOK = MarshalByRefObject.CanCastToXmlTypeHelper(rtType, (MarshalByRefObject)o); } } } // This is a well known object which does not have a backing ObjRef else { fCastOK = CanCastToWK(rtType); } return(fCastOK); }
// Initialize a lifetime service object for a marshal-by-ref object. internal static Object InitializeLifetimeService(MarshalByRefObject obj) { Manager manager = GetLifetimeManager(); ILease lease = manager.GetLeaseForObject(obj); if(lease != null) { return lease; } return new Lease(obj, LeaseTime, RenewOnCallTime, SponsorshipTimeout); }
public static System.Runtime.Remoting.Activation.IConstructionReturnMessage CreateConstructionReturnMessage(System.Runtime.Remoting.Activation.IConstructionCallMessage ctorMsg, MarshalByRefObject retObj) { Contract.Ensures(Contract.Result <System.Runtime.Remoting.Activation.IConstructionReturnMessage>() != null); return(default(System.Runtime.Remoting.Activation.IConstructionReturnMessage)); }
// Constructor. public Lease(MarshalByRefObject obj, TimeSpan leaseTime, TimeSpan renewOnCallTime, TimeSpan sponsorshipTimeout) { this.obj = obj; this.initialLeaseTime = leaseTime; this.renewOnCallTime = renewOnCallTime; this.sponsorshipTimeout = sponsorshipTimeout; this.state = LeaseState.Initial; }
/// <summary> /// NKRemoteServerDynamicProperty constructor. /// </summary> /// <param name="obj"> Represents the remoted object</param> /// <param name="ctx"> Represtns the context of call.</param> public RemoteServerDynamicProperty(MarshalByRefObject obj, Context ctx) { }
public static String[] GetUrlsForObject(MarshalByRefObject obj) { // TODO return null; }
// Attach this proxy to a remote server. protected void AttachServer(MarshalByRefObject s) { serverObject = s; }
private void buttonConnect_Click(object sender, EventArgs e) { try { if (buttonConnect.Text == "Connect") { // Creates a client object that 'lives' here on the client. client = new RemotingClient(); listBoxLog.Items.Add("Created client with ID " + client.ClientID); // Hook into the event exposed on the Sink object so we can transfer a server // message through to this class. client.clientCallback += OnMessageReceived; // Hook into the event to allow the server to send (other) notifications // (Currently only asserted when clients connect or disconnect from server by // means of registering respective event handlers associated with their client // references) client.serverNotificationCallback += OnServerNotification; if (channel == null) { int clientChannel = FindUnusedPort(IPAddress.Loopback); listBoxLog.Items.Add("Using (unused) client port " + clientChannel); if (clientChannel != 0) { BinaryServerFormatterSinkProvider serverProv = new BinaryServerFormatterSinkProvider(); serverProv.TypeFilterLevel = System.Runtime.Serialization.Formatters.TypeFilterLevel.Full; BinaryClientFormatterSinkProvider clientProv = new BinaryClientFormatterSinkProvider(); IDictionary props = new Hashtable(); props["port"] = clientChannel; // Register a client channel so the server an communicate back - it needs a channel // opened for the callback to the CallbackSink object that is anchored on the client! // channel = new HttpChannel(clientChannel++); channel = new HttpChannel(props, clientProv, serverProv); } else { throw new Exception("Couldn't find unused client port!"); } } // Registers a channel with the channel services ChannelServices.RegisterChannel(channel, false); // Now create a transparent proxy to the server component MarshalByRefObject obj = (MarshalByRefObject)RemotingServices.Connect(typeof(RemotingServer), "http://" + textBoxServerIPAddress.Text + ":" + textBoxServerPortConnect.Text + "/Server"); server = obj as RemotingServer; // Create messaging callback objects clientCallback = new RemotingClient.ClientCallback(client.SendMessage); // Register callback if (clientCallback != null) { // Simple messaging callback for broadcasting of messages from one client server.RegisterMessageCallback(clientCallback); // Messaging callback associated with the client to allow for sending messages to a particular client server.RegisterMessageCallback(clientCallback, client); } buttonConnect.Text = "Disconnect"; textBoxServerIPAddress.Enabled = false; textBoxServerPortConnect.Enabled = false; foreach (Control control in tabPageServer.Controls) { control.Enabled = false; } } else { if (server != null) { if (clientCallback != null) { server.UnregisterMessageCallback(clientCallback); } if (client != null) { server.UnregisterMessageCallback(client); } } if (client != null) { client.clientCallback -= OnMessageReceived; client.serverNotificationCallback -= OnServerNotification; } if (channel != null) { ChannelDataStore cds = (ChannelDataStore)channel.ChannelData; foreach (string s in cds.ChannelUris) { channel.StopListening(s); } ChannelServices.UnregisterChannel(channel); } clientCallback = null; server = null; client = null; channel = null; OnServerNotification(); buttonConnect.Text = "Connect"; textBoxServerIPAddress.Enabled = true; textBoxServerPortConnect.Enabled = true; foreach (Control control in tabPageServer.Controls) { control.Enabled = true; } } } catch (Exception ex) { listBoxLog.Items.Add(ex.Message); } }
[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
internal static IMethodReturnMessage InternalExecuteMessage( MarshalByRefObject target, IMethodCallMessage reqMsg) { ReturnMessage result; Type tt = target.GetType(); MethodBase method; if (reqMsg.MethodBase.DeclaringType == tt || reqMsg.MethodBase == FieldSetterMethod || reqMsg.MethodBase == FieldGetterMethod) { method = reqMsg.MethodBase; } else { method = GetVirtualMethod(tt, reqMsg.MethodBase); if (method == null) { throw new RemotingException( String.Format("Cannot resolve method {0}:{1}", tt, reqMsg.MethodName)); } } if (reqMsg.MethodBase.IsGenericMethod) { Type[] genericArguments = reqMsg.MethodBase.GetGenericArguments(); MethodInfo gmd = ((MethodInfo)method).GetGenericMethodDefinition(); method = gmd.MakeGenericMethod(genericArguments); } object oldContext = CallContext.SetCurrentCallContext(reqMsg.LogicalCallContext); try { object [] out_args; object rval = InternalExecute(method, target, reqMsg.Args, out out_args); // Collect parameters with Out flag from the request message // FIXME: This can be done in the unmanaged side and will be // more efficient ParameterInfo[] parameters = method.GetParameters(); object[] returnArgs = new object [parameters.Length]; int n = 0; int noa = 0; foreach (ParameterInfo par in parameters) { if (par.IsOut && !par.ParameterType.IsByRef) { returnArgs [n++] = reqMsg.GetArg(par.Position); } else if (par.ParameterType.IsByRef) { returnArgs [n++] = out_args [noa++]; } else { returnArgs [n++] = null; } } result = new ReturnMessage(rval, returnArgs, n, CallContext.CreateLogicalCallContext(true), reqMsg); } catch (Exception e) { result = new ReturnMessage(e, reqMsg); } CallContext.RestoreCallContext(oldContext); return(result); }
public static IMethodReturnMessage ExecuteMessage ( MarshalByRefObject target, IMethodCallMessage reqMsg) { if (IsTransparentProxy(target)) { // Message must go through all chain of sinks RealProxy rp = GetRealProxy (target); return (IMethodReturnMessage) rp.Invoke (reqMsg); } else // Direct call return InternalExecuteMessage (target, reqMsg); }
public static ObjRef Marshal(MarshalByRefObject Obj) { return(Marshal(Obj, null, null)); }
public static string GetObjectUri (MarshalByRefObject obj) { Identity ident = GetObjectIdentity(obj); if (ident is ClientIdentity) return ((ClientIdentity)ident).TargetUri; else if (ident != null) return ident.ObjectUri; else return null; }
public static ObjRef Marshal(MarshalByRefObject Obj, string URI) { return(Marshal(Obj, URI, null)); }
public static ObjRef Marshal (MarshalByRefObject Obj, string URI) { return Marshal (Obj, URI, null); }
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); }
public static ObjRef GetObjRefForProxy(MarshalByRefObject obj) { Identity ident = GetObjectIdentity(obj); if (ident == null) return null; else return ident.CreateObjRef(null); }
public AopProxyBase CreateAopProxyInstance(MarshalByRefObject obj, Type type) { return(new AopControlProxy(obj, type)); }
public static void SetObjectUriForMarshal(MarshalByRefObject obj, string uri) { if (IsTransparentProxy (obj)) { RealProxy proxy = RemotingServices.GetRealProxy(obj); Identity identity = proxy.ObjectIdentity; if (identity != null && !(identity is ServerIdentity) && !proxy.GetProxiedType().IsContextful) throw new RemotingException ("SetObjectUriForMarshal method should only be called for MarshalByRefObjects that exist in the current AppDomain."); } Marshal (obj, uri); }
internal IMessageSink CreateServerObjectSinkChain (MarshalByRefObject obj, bool forceInternalExecute) { IMessageSink objectSink = new StackBuilderSink (obj, forceInternalExecute); objectSink = new ServerObjectTerminatorSink (objectSink); objectSink = new Lifetime.LeaseSink (objectSink); if (context_properties != null) { // Contribute object sinks in reverse order for (int n = context_properties.Count-1; n >= 0; n--) { IContextProperty prop = (IContextProperty) context_properties[n]; IContributeObjectSink contributor = prop as IContributeObjectSink; if (contributor != null) objectSink = contributor.GetObjectSink (obj, objectSink); } } return objectSink; }
internal static ClientActivatedIdentity CreateClientActivatedServerIdentity(MarshalByRefObject realObject, Type objectType, string objectUri) { ClientActivatedIdentity identity = new ClientActivatedIdentity (objectUri, objectType); identity.AttachServerObject (realObject, Context.DefaultContext); RegisterServerIdentity (identity); identity.StartTrackingLifetime ((ILease)realObject.InitializeLifetimeService ()); return identity; }
public DynamicProxy(T target) : base(typeof(T)) { _target = target; }
public static string[] GetUrlsForObject (MarshalByRefObject obj) { string uri = RemotingServices.GetObjectUri (obj); if (uri == null) return new string [0]; ArrayList list = new ArrayList (); lock (registeredChannels.SyncRoot) { foreach (object chnl_obj in registeredChannels) { if (chnl_obj is CrossAppDomainChannel) continue; IChannelReceiver chnl = chnl_obj as IChannelReceiver; if (chnl != null) list.AddRange (chnl.GetUrlsForUri (uri)); } } return (string[]) list.ToArray (typeof(string)); }
internal virtual IMessageSink GetObjectChain(IMessage reqMsg, out MarshalByRefObject obj) { ServerIdentity srvID = GetServerIdentity(reqMsg); return(srvID.GetServerObjectChain(out obj)); }
public void getFacetTest2() { IComponentServant target = new IComponentServant(context); MarshalByRefObject actual = target.getFacet("IDL:invalid/interface:1.0"); }
public GenericMessageSink(MarshalByRefObject obj, IMessageSink nextSink, string type) { _type = type; _next = nextSink; }
internal IMessageSink CreateEnvoySink (MarshalByRefObject serverObject) { IMessageSink sink = EnvoyTerminatorSink.Instance; if (context_properties != null) { foreach (IContextProperty prop in context_properties) { IContributeEnvoySink contributor = prop as IContributeEnvoySink; if (contributor != null) sink = contributor.GetEnvoySink (serverObject, sink); } } return sink; }
public System.Runtime.Remoting.Messaging.IMessageSink GetObjectSink(MarshalByRefObject obj, System.Runtime.Remoting.Messaging.IMessageSink nextSink) { return(new InterceptMethodCalls(nextSink)); }