Exemplo n.º 1
0
        public override IMessage Invoke(IMessage msg)
        {
            if (msg != null)
            {
                if (msg is IConstructionCallMessage)
                {
                    IConstructionCallMessage constructCallMsg = msg as IConstructionCallMessage;

                    RealProxy defaultProxy = RemotingServices.GetRealProxy(_target);

                    // 如果不做下面这一步,_target还是一个没有直正实例化被代理对象的透明代理,
                    // 这样的话,会导致没有直正构建对象。
                    defaultProxy.InitializeServerObject(constructCallMsg);

                    // 本类是一个RealProxy,它可通过GetTransparentProxy函数得到透明代理
                    return(System.Runtime.Remoting.Services.EnterpriseServicesHelper.CreateConstructionReturnMessage(constructCallMsg, (MarshalByRefObject)GetTransparentProxy()));
                }
                else if (msg is IMethodCallMessage)
                {
                    IMethodCallMessage callMsg = msg as IMethodCallMessage;
                    object[]           args    = callMsg.Args;

                    // System.Windows.Forms.MessageBox.Show(callMsg.MethodBase.ToString());

                    if (callMsg.MethodName.StartsWith(" set_ ") && args.Length == 1)
                    {
                        method.Invoke(_target, new object[] { callMsg.MethodName.Substring(4), args[0] }); // 对属性进行调用
                                            
                    }
                    return(RemotingServices.ExecuteMessage(_target, callMsg));
                }
            }
            return(msg);
        }
Exemplo n.º 2
0
        public static void Main()
        {
            Console.WriteLine("");
            Console.WriteLine("CustomProxy Sample");
            Console.WriteLine("================");
            Console.WriteLine("");
// <Snippet8>
// <Snippet9>
// <Snippet10>
            // Create an instance of MyProxy.
            MyProxy myProxyInstance = new MyProxy(typeof(CustomServer));
            // Get a CustomServer proxy.
            CustomServer myHelloServer = (CustomServer)myProxyInstance.GetTransparentProxy();

// </Snippet10>
            // Get stubdata.
            Console.WriteLine("GetStubData = " + RealProxy.GetStubData(myProxyInstance).ToString());
// </Snippet9>
            // Get ProxyType.
            Console.WriteLine("Type of object represented by RealProxy is :"
                              + myProxyInstance.GetProxiedType());
// </Snippet8>
            myHelloServer.HelloMethod("RealProxy Sample");
            Console.WriteLine("");
            // Get a reference object from server.
            Console.WriteLine("Create an objRef object to be marshalled across Application Domains...");
            ObjRef CustomObjRef = myProxyInstance.CreateObjRef(typeof(CustomServer));

            Console.WriteLine("URI of 'ObjRef' object =  " + CustomObjRef.URI);
        }
Exemplo n.º 3
0
 internal SCUnMarshaler(Type _servertype, byte[] _buffer)
 {
     buffer        = _buffer;
     servertype    = _servertype;
     _rp           = null;
     _fUnMarshaled = false;
 }
Exemplo n.º 4
0
        private RealProxy UnmarshalRemoteReference()
        {
            DBG.Info(DBG.SC, "SCM: UnmarshalRemoteReference()");
            IntPtr    pUnk = IntPtr.Zero;
            RealProxy rp   = null;

            try
            {
                _fUnMarshaled = true;
                if (buffer != null)
                {
                    pUnk = Thunk.Proxy.UnmarshalObject(buffer);
                }

                // set up a remote serviced component proxy
                rp = new RemoteServicedComponentProxy(servertype, pUnk, false);
            }
            finally
            {
                // now get rid of the pUnk
                if (pUnk != IntPtr.Zero)
                {
                    Marshal.Release(pUnk);
                }
                // if we have the dcom buffer get rid of it
                buffer = null;
            }

            return(rp);
        }
Exemplo n.º 5
0
        /// <summary>
        /// 實現Invoke方法
        /// </summary>
        /// <param name="msg"></param>
        /// <returns></returns>
        public override IMessage Invoke(IMessage msg)
        {
            IMethodReturnMessage methodReturnMessage = null;
            IMethodCallMessage   methodCallMessage   = msg as IMethodCallMessage;

            if (methodCallMessage != null)
            {
                IConstructionCallMessage constructionCallMessage = methodCallMessage as IConstructionCallMessage;
                if (constructionCallMessage != null)
                {
                    RealProxy defaultProxy = RemotingServices.GetRealProxy(_target);
                    defaultProxy.InitializeServerObject(constructionCallMessage);
                    methodReturnMessage = EnterpriseServicesHelper.CreateConstructionReturnMessage(constructionCallMessage, (MarshalByRefObject)GetTransparentProxy());
                }
                else
                {
                    _interception.PreInvoke(methodCallMessage);
                    try
                    {
                        methodReturnMessage = RemotingServices.ExecuteMessage(_target, methodCallMessage);
                    }
                    catch { }
                    if (methodReturnMessage.Exception != null)
                    {
                        _interception.ExceptionHandle(methodReturnMessage);
                    }
                    else
                    {
                        _interception.PostInvoke(methodReturnMessage);
                    }
                }
            }
            return(methodReturnMessage);
        }
Exemplo n.º 6
0
        public override Object GetRealObject(StreamingContext context)
        {
            DBG.Info(DBG.SC, "SCM: GetRealObject()");

            if (!IsMarshaledObject)
            {
                DBG.Info(DBG.SC, "SCM: GetRealObject() returning objref!");
                return(this);
            }
            else
            {
                if (IsFromThisProcess() && !ServicedComponentInfo.IsTypeEventSource(_rt))
                {
                    Object otp = base.GetRealObject(context);
                    // We need to notify the object that there is a managed reference.
                    ((ServicedComponent)otp).DoSetCOMIUnknown(IntPtr.Zero);

                    return(otp);
                }
                else
                {
                    if (_rp == null)
                    {
                        _rp = _um.GetRealProxy();
                    }
                    DBG.Assert(_rp != null, "GetRealObject on a marshaller with no proxy!");
                    return(_rp.GetTransparentProxy());
                }
            }
        }
Exemplo n.º 7
0
        public override IMessage Invoke(IMessage msg)
        {
            IMethodCallMessage       call   = msg as IMethodCallMessage;
            IConstructionCallMessage ctor   = msg as IConstructionCallMessage;
            IMethodReturnMessage     result = null;

            if (ctor != null)               // 呼び出し関数がコンストラクタの場合

            {
                _behavior.PreInitializer(ctor);

                RealProxy rp = RemotingServices.GetRealProxy(_target);
                rp.InitializeServerObject(ctor);
                MarshalByRefObject tp = this.GetTransparentProxy() as MarshalByRefObject;
                result = EnterpriseServicesHelper.CreateConstructionReturnMessage(ctor, tp);

                _behavior.PostInitializer(ctor);
            }
            else if (call != null)                 // 通常関数の場合

            {
                _behavior.PreCallMethod(call);

                result = RemotingServices.ExecuteMessage(this._target, call);

                _behavior.PostCallMethod(call);
            }
            else
            {
                Console.WriteLine($"メソッドの実行に失敗しました:{msg}");
                //throw new Exception($"メソッドの実行に失敗しました:{msg}");
            }

            return(result);
        }
Exemplo n.º 8
0
 static DynamicPropertyCollection GetDynamicPropertyCollection(ContextBoundObject obj, Context ctx)
 {
     if (ctx == null && obj != null)
     {
         if (RemotingServices.IsTransparentProxy(obj))
         {
             RealProxy rp = RemotingServices.GetRealProxy(obj);
             return(rp.ObjectIdentity.ClientDynamicProperties);
         }
         else
         {
             return(obj.ObjectIdentity.ServerDynamicProperties);
         }
     }
     else if (ctx != null && obj == null)
     {
         if (ctx.context_dynamic_properties == null)
         {
             ctx.context_dynamic_properties = new DynamicPropertyCollection();
         }
         return(ctx.context_dynamic_properties);
     }
     else if (ctx == null && obj == null)
     {
         if (global_dynamic_properties == null)
         {
             global_dynamic_properties = new DynamicPropertyCollection();
         }
         return(global_dynamic_properties);
     }
     else
     {
         throw new ArgumentException("Either obj or ctx must be null");
     }
 }
        public TEntity GenEntityProxy <TEntity>()
        {
            RealProxy <TEntity> realProxy = new RealProxy <TEntity>();

            realProxy.GetPropertyEvent += GetPropertyValue;
            return(realProxy.Entity);
        }
Exemplo n.º 10
0
        internal Object GetValueNoThrow(String name, Type type)
        {
            Type   foundType;
            Object value;

            BCLDebug.Assert(null != type, "[SerializationInfo.GetValue]type ==null");

            value = GetElementNoThrow(name, out foundType);
            if (value == null)
            {
                return(null);
            }
            if (RemotingServices.IsTransparentProxy(value))
            {
                RealProxy proxy = RemotingServices.GetRealProxy(value);
                if (RemotingServices.ProxyCheckCast(proxy, type))
                {
                    return(value);
                }
            }
            else if (foundType == type || type.IsAssignableFrom(foundType) || value == null)
            {
                return(value);
            }

            BCLDebug.Assert(m_converter != null, "[SerializationInfo.GetValue]m_converter!=null");

            return(m_converter.Convert(value, type));
        }
 internal SCUnMarshaler(Type _servertype, byte[] _buffer)
 {
     this.buffer        = _buffer;
     this.servertype    = _servertype;
     this._rp           = null;
     this._fUnMarshaled = false;
 }
Exemplo n.º 12
0
        static void Main(string[] args)
        {
            //test();

            Console.WriteLine("");
            Console.WriteLine("CustomProxy Sample");
            Console.WriteLine("================");
            Console.WriteLine("");
            // Create an instance of MyProxy.
            DynamicProxy myProxyInstance = new DynamicProxy(typeof(Cicada));
            // Get a CustomServer proxy.
            IAnimal myHelloServer = (Cicada)myProxyInstance.GetTransparentProxy();

            // Get stubdata.
            Console.WriteLine("GetStubData = " + RealProxy.GetStubData(myProxyInstance).ToString());
            // Get ProxyType.
            Console.WriteLine("Type of object represented by RealProxy is :"
                              + myProxyInstance.GetProxiedType());
            //myHelloServer.HelloMethod("RealProxy Sample");
            myHelloServer.Eating();
            //Console.WriteLine("");
            // Get a reference object from server.
            //Console.WriteLine("Create an objRef object to be marshalled across Application Domains...");
            //ObjRef CustomObjRef = myProxyInstance.CreateObjRef(typeof(CustomServer));
            //Console.WriteLine("URI of 'ObjRef' object =  " + CustomObjRef.URI);
        }
Exemplo n.º 13
0
        public override IMessage Invoke(IMessage msg)
        {
            var ctr = msg as IConstructionCallMessage;

            if (ctr != null)
            {
                Console.WriteLine("ctr");
                RealProxy _proxy = RemotingServices.GetRealProxy(this._target);
                _proxy.InitializeServerObject(ctr);
                MarshalByRefObject tp = (MarshalByRefObject)this.GetTransparentProxy();
                return(EnterpriseServicesHelper.CreateConstructionReturnMessage(ctr, tp));
            }

            if (_intercepts != null)
            {
                foreach (var _intercept in _intercepts)
                {
                    _intercept.Do();
                }
            }
            var call = msg as IMethodCallMessage;

            Console.WriteLine(string.Format("proxy method:{0}", call.MethodName));
            var result = call.MethodBase.Invoke(this._target, call.Args);

            return(new ReturnMessage(result, new object[0], 0, null, call));
        }
Exemplo n.º 14
0
        ///<summary>
        /// checks, whether <paramref name="target"/> supports the methods of <paramref name="requiredType"/>.
        /// Supports testing transparent proxies.
        ///</summary>
        ///<param name="target">the target instance or <c>null</c></param>
        ///<param name="targetName">the name of the target to be used in error messages</param>
        ///<param name="requiredType">the type to test for</param>
        /// <exception cref="ArgumentNullException">
        /// if <paramref name="requiredType"/> is <c>null</c>
        /// </exception>
        /// <exception cref="NotSupportedException">
        /// if it is not possible to invoke methods of
        /// type <paramref name="requiredType"/> on <paramref name="target"/>
        /// </exception>
        public static void Understands(object target, string targetName, Type requiredType)
        {
            ArgumentNotNull(requiredType, "requiredType");

            if (target == null)
            {
                throw new NotSupportedException(string.Format(CultureInfo.InvariantCulture, "Target '{0}' is null.", targetName));
            }

            Type targetType;

            if (RemotingServices.IsTransparentProxy(target))
            {
                RealProxy         rp  = RemotingServices.GetRealProxy(target);
                IRemotingTypeInfo rti = rp as IRemotingTypeInfo;
                if (rti != null)
                {
                    if (rti.CanCastTo(requiredType, target))
                    {
                        return;
                    }
                    throw new NotSupportedException(string.Format(CultureInfo.InvariantCulture, "Target '{0}' is a transparent proxy that does not support methods of '{1}'.", targetName, requiredType.FullName));
                }
                targetType = rp.GetProxiedType();
            }
            else
            {
                targetType = target.GetType();
            }

            if (!requiredType.IsAssignableFrom(targetType))
            {
                throw new NotSupportedException(string.Format(CultureInfo.InvariantCulture, "Target '{0}' of type '{1}' does not support methods of '{2}'.", targetName, targetType, requiredType.FullName));
            }
        }
Exemplo n.º 15
0
        //
        // The user should call one of these getters to get the data back in the
        // form requested.
        //

        /// <include file='doc\SerializationInfo.uex' path='docs/doc[@for="SerializationInfo.GetValue"]/*' />
        public Object   GetValue(String name, Type type)
        {
            Type   foundType;
            Object value;

            if (null == type)
            {
                throw new ArgumentNullException("type");
            }

            value = GetElement(name, out foundType);
            if (RemotingServices.IsTransparentProxy(value))
            {
                RealProxy proxy = RemotingServices.GetRealProxy(value);
                if (RemotingServices.ProxyCheckCast(proxy, type))
                {
                    return(value);
                }
            }
            else if (foundType == type || type.IsAssignableFrom(foundType) || value == null)
            {
                return(value);
            }

            BCLDebug.Assert(m_converter != null, "[SerializationInfo.GetValue]m_converter!=null");

            return(m_converter.Convert(value, type));
        }
        private void DemoProxy()
        {
            IDemoProxy proxy = new RealProxy();

            proxy.IndsætString("Peter");
            proxy.IndsætString("Jakob");
            proxy.IndsætString("Vibeke");
            proxy.IndsætString("Mohammed");

            foreach (string s in proxy.Hent())
            {
                Console.WriteLine(s);
            }

            Console.WriteLine("    EFTER PROXY ");

            // SWC
            IDemoProxy proxy2 = new ProxyKlasse("SWC");

            proxy2.IndsætString("Peter");
            proxy2.IndsætString("Mohammed");

            foreach (string s in proxy2.Hent())
            {
                Console.WriteLine(s);
            }
        }
Exemplo n.º 17
0
 internal ServicedComponentMarshaler(MarshalByRefObject o, Type requestedType)
     : base(o, requestedType)
 {
     DBG.Assert(RemotingServices.IsTransparentProxy(o), "IsTransparentProxy failed");
     _rp = RemotingServices.GetRealProxy(o);
     _rt = requestedType;
 }
Exemplo n.º 18
0
 public override IMessage Invoke(IMessage msg)
 {
     if (msg is IConstructionCallMessage)
     {
         IConstructionCallMessage   constructCallMsg          = msg as IConstructionCallMessage;
         IConstructionReturnMessage constructionReturnMessage = this.InitializeServerObject((IConstructionCallMessage)msg);
         RealProxy.SetStubData(this, constructionReturnMessage.ReturnValue);
         Console.WriteLine("Call constructor");
         return(constructionReturnMessage);
     }
     else
     {
         IMethodCallMessage callMsg = msg as IMethodCallMessage;
         IMessage           message;
         try
         {
             Console.WriteLine(callMsg.MethodName + "执行前。。。");
             object[] args = callMsg.Args;
             object   o    = callMsg.MethodBase.Invoke(GetUnwrappedServer(), args);
             Console.WriteLine(callMsg.MethodName + "执行后。。。");
             message = new ReturnMessage(o, args, args.Length, callMsg.LogicalCallContext, callMsg);
         }
         catch (Exception e)
         {
             message = new ReturnMessage(e, callMsg);
         }
         Console.WriteLine(message.Properties["__Return"]);
         return(message);
     }
 }
        private void DemoProxy()
        {
            IDemoProxy proxy = new RealProxy();

            proxy.InsertString("Peter");
            proxy.InsertString("Anders");
            proxy.InsertString("Vibeke");
            proxy.InsertString("Michael C");

            foreach (string s in proxy.GetAll())
            {
                Console.WriteLine(s);
            }

            Console.WriteLine("    AFTER PROXY ");
            IDemoProxy proxy2 = new ProxyClass("SWC");

            proxy2.InsertString("Peter");
            proxy2.InsertString("Anders");

            foreach (string s in proxy2.GetAll())
            {
                Console.WriteLine(s);
            }
        }
        MarshalByRefObject ICustomFactory.CreateInstance(Type serverType)
        {
            RealProxy realProxy = null;

            ServicedComponentProxy.CleanupQueues(false);
            int  num               = ServicedComponentInfo.SCICachedLookup(serverType);
            bool fIsJitActivated   = (num & 8) != 0;
            bool fIsPooled         = (num & 0x10) != 0;
            bool fAreMethodsSecure = (num & 0x20) != 0;

            if (fIsJitActivated)
            {
                object obj2 = IdentityTable.FindObject(Proxy.GetCurrentContextToken());
                if (obj2 != null)
                {
                    realProxy = RemotingServices.GetRealProxy(obj2);
                }
            }
            if (realProxy == null)
            {
                realProxy = new ServicedComponentProxy(serverType, fIsJitActivated, fIsPooled, fAreMethodsSecure, true);
            }
            else if (realProxy is ServicedComponentProxy)
            {
                ((ServicedComponentProxy)realProxy).ConstructServer();
            }
            return((MarshalByRefObject)realProxy.GetTransparentProxy());
        }
Exemplo n.º 21
0
        internal Object GetValueNoThrow(String name, Type type)
        {
            Type   foundType;
            Object value;

            Contract.Assert((object)type != null, "[SerializationInfo.GetValue]type ==null");
            Contract.Assert(type is RuntimeType, "[SerializationInfo.GetValue]type is not a runtime type");

            value = GetElementNoThrow(name, out foundType);
            if (value == null)
            {
                return(null);
            }
#if FEATURE_REMOTING
            if (RemotingServices.IsTransparentProxy(value))
            {
                RealProxy proxy = RemotingServices.GetRealProxy(value);
                if (RemotingServices.ProxyCheckCast(proxy, (RuntimeType)type))
                {
                    return(value);
                }
            }
            else
#endif
            if (Object.ReferenceEquals(foundType, type) || type.IsAssignableFrom(foundType) || value == null)
            {
                return(value);
            }

            Contract.Assert(m_converter != null, "[SerializationInfo.GetValue]m_converter!=null");

            return(m_converter.Convert(value, type));
        }
        public override IMessage Invoke(IMessage msg)
        {
            IMethodCallMessage                  call = (IMethodCallMessage)msg;
            IConstructionCallMessage            ctor = call as IConstructionCallMessage;
            List <Action <IMethodCallMessage> > OnMethodExecuting = new List <Action <IMethodCallMessage> >();
            List <Action <IMethodCallMessage, IMethodReturnMessage> > OnMethodExecuted = new List <Action <IMethodCallMessage, IMethodReturnMessage> >();

            IMethodReturnMessage returnMessage = null;

            if (ctor != null)
            {
                //构造函数
                //获取最底层的默认真实代理
                RealProxy default_proxy = RemotingServices.GetRealProxy(this.target);
                default_proxy.InitializeServerObject(ctor);
                MarshalByRefObject tp = (MarshalByRefObject)this.GetTransparentProxy(); //自定义的透明代理 this
                returnMessage = EnterpriseServicesHelper.CreateConstructionReturnMessage(ctor, tp);
            }
            else
            {
                //方法
                object returnObject = null;
                if (!Intercept(call, ref returnObject, ref OnMethodExecuting, ref OnMethodExecuted))
                {
                    if (returnObject is IMethodReturnMessage)
                    {
                        returnMessage = (IMethodReturnMessage)returnObject;
                    }
                    else
                    {
                        if (returnObject == null)
                        {
                            var method     = (MethodInfo)call.MethodBase;
                            var returnType = method.ReturnType;
                            if (returnType != typeof(void))
                            {
                                returnObject = returnType.IsValueType ? Activator.CreateInstance(returnType) : null;
                            }
                        }
                        returnMessage = new ReturnMessage(returnObject, call.Args, call.ArgCount, call.LogicalCallContext, call);
                    }
                }
                else
                {
                    OnMethodExecuting.ForEach((method) => { method(call); });
                    OnMethodExecuting.Clear();
                    try
                    {
                        returnMessage = RemotingServices.ExecuteMessage(this.target, call);
                    }
                    catch (Exception e)
                    {
                        returnMessage = new ReturnMessage(e, call);
                    }
                    OnMethodExecuted.ForEach((method) => { method(call, returnMessage); });
                    OnMethodExecuted.Clear();
                }
            }
            return(returnMessage);
        }
Exemplo n.º 23
0
        /// <include file='doc\ServicedComponent.uex' path='docs/doc[@for="ServicedComponent.DisposeObject"]/*' />
        public static void DisposeObject(ServicedComponent sc)
        {
            RealProxy rp = RemotingServices.GetRealProxy(sc);

            if (rp is ServicedComponentProxy)
            {
                DBG.Info(DBG.SC, "DisposeObject(): Disposing ServicedComponentProxy");

                ServicedComponentProxy scp = (ServicedComponentProxy)rp;

                RemotingServices.Disconnect(sc);

                // dispose the actual proxy
                scp.Dispose(true);
            }
            else if (rp is RemoteServicedComponentProxy)
            {
                DBG.Info(DBG.SC, "DisposeObject(): Disposing RemoteServicedComponentProxy");

                RemoteServicedComponentProxy rscp = (RemoteServicedComponentProxy)rp;

                // dispose the remote instance first

                sc.Dispose();

                // then dispose the local proxy

                rscp.Dispose(true);
            }
            else     // We're off in magic land, with no proxy of our own.
            {
                sc.Dispose();
            }
        }
        public virtual void GetObjectData(Object obj, SerializationInfo info, StreamingContext context)
        {
            if (obj == null)
            {
                throw new ArgumentNullException("obj");
            }

            if (info == null)
            {
                throw new ArgumentNullException("info");
            }

            //
            // This code is to special case marshalling types inheriting from RemotingClientProxy
            // Check whether type inherits from RemotingClientProxy and serialize the correct ObjRef
            // after getting the correct proxy to the actual server object
            //

            Message.DebugOut("RemotingSurrogate::GetObjectData obj.Type: " + obj.GetType().FullName + " \n");
            if (RemotingServices.IsTransparentProxy(obj))
            {
                RealProxy rp = RemotingServices.GetRealProxy(obj);
                rp.GetObjectData(info, context);
            }
            else
            {
                RemotingServices.GetObjectData(obj, info, context);
            }
        }
Exemplo n.º 25
0
        public void GetRealProxy()
        {
            TcpChannel chn = null;

            try
            {
                chn = new TcpChannel(1241);
                ChannelServices.RegisterChannel(chn);

                RemotingConfiguration.RegisterWellKnownServiceType(typeof(MarshalObject), "MonoTests.System.Runtime.Remoting.RemotingServicesTest.MarshalObject.soap", WellKnownObjectMode.Singleton);

                MyProxy       proxy  = new  MyProxy(typeof(MarshalObject), (MarshalByRefObject)Activator.GetObject(typeof(MarshalObject), "tcp://localhost:1241/MonoTests.System.Runtime.Remoting.RemotingServicesTest.MarshalObject.soap"));
                MarshalObject objRem = (MarshalObject)proxy.GetTransparentProxy();

                RealProxy rp = RemotingServices.GetRealProxy(objRem);

                Assert.IsTrue(rp != null, "#A12");
                Assert.AreEqual("MonoTests.System.Runtime.Remoting.RemotingServicesInternal.MyProxy", rp.GetType().ToString(), "#A13");
            }
            finally
            {
                if (chn != null)
                {
                    ChannelServices.UnregisterChannel(chn);
                }
            }
        }
Exemplo n.º 26
0
        //覆写Invoke,处理RealProxy截获的各种消息,
        //此种方式最简捷,但不能截获远程对象的激活,好在我们并不是真的要Remoting
        public override IMessage Invoke(IMessage msg)
        {
            var call = msg as IMethodCallMessage;
            IConstructionCallMessage ctr  = call as IConstructionCallMessage;
            IMethodReturnMessage     back = null;

            //构造函数,只有ContextBoundObject(Inherit from MarshalByRefObject)对象才能截获构造函数
            if (ctr != null)
            {
                RealProxy defaultProxy = RemotingServices.GetRealProxy(_target);
                //如果不做下面这一步,_target还是一个没有直正实例化被代理对象的透明代理,
                //这样的话,会导致没有直正构建对象。
                defaultProxy.InitializeServerObject(ctr);
                //本类是一个RealProxy,它可通过GetTransparentProxy函数得到透明代理
                back = EnterpriseServicesHelper.CreateConstructionReturnMessage(ctr, (MarshalByRefObject)GetTransparentProxy());
            }
            //MarshalByRefObject对象就可截获普通的调用消息,
            //MarshalByRefObject对象告诉编译器,不能将其内部简单的成员函数优化成内联代码,
            //这样才能保证函数调用都能截获。
            else
            {
                IDictionary <string, object> dic = new Dictionary <string, object>();
                dic = call.Args[0] as IDictionary <string, object>;
                if (dic != null & dic.Count > 0)
                {
                    foreach (var m in dic)
                    {
                    }
                }
                back = RemotingServices.ExecuteMessage(_target, call);
            }
            return(back);
        }
Exemplo n.º 27
0
        // TODO:  Move to ServicedComponent static method
        public static void DeactivateObject(Object otp, bool disposing)
        {
            RealProxy rp = RemotingServices.GetRealProxy(otp);
            ServicedComponentProxy scp = rp as ServicedComponentProxy;

            DBG.Assert(scp != null, "CS.DeactivateObject called on a non-ServicedComponentProxy");

            if (!scp.IsProxyDeactivated)
            {
                DBG.Assert(scp.HomeToken == Thunk.Proxy.GetCurrentContextToken(), "Deactivate called from wrong context");

                if (scp.IsObjectPooled)
                {
                    DBG.Info(DBG.SC, "CS.DeactivateObject calling ReconnectForPooling");
                    ReconnectForPooling(scp);
                }

                // this would wack the real server also so do this last

                DBG.Info(DBG.SC, "CS.DeactivateObject calling scp.DeactivateProxy");
                scp.DeactivateProxy(disposing);
            }

            DBG.Assert(scp.IsProxyDeactivated, "scp not deactive");
        }
Exemplo n.º 28
0
        public override IMessage Invoke(IMessage msg)
        {
            IMethodCallMessage   callMsg = msg as IMethodCallMessage;
            IMethodReturnMessage retMsg  = null;
            bool fLog = false;

            //메서드 시작 로그
            fLog = MethodEnterLog(callMsg);

            // 생성자 메서드 일경우
            if (msg is IConstructionCallMessage)
            {
                // 객체 생성 메시지 처리
                IConstructionCallMessage ctorMsg = (IConstructionCallMessage)msg;
                RealProxy proxy = RemotingServices.GetRealProxy(target);
                // 실제 객체를 생성한다.
                proxy.InitializeServerObject(ctorMsg);
                // 객체 생성 결과를 ‘만들어’ 반환한다.
                retMsg = EnterpriseServicesHelper.CreateConstructionReturnMessage(ctorMsg, (MarshalByRefObject)this.GetTransparentProxy());
            }
            //일반 메서드
            else if (msg is IMethodCallMessage)
            {
                /*
                 * // 파라메터 있는 메서드와 아닌 메서드 나눌때
                 * if (callMsg.ArgCount > 0)
                 * {
                 *  // 파라메터 리스트 작성
                 *  Console.WriteLine("Parameter list :");
                 *
                 *  for (int i = 0; i < callMsg.ArgCount; i++)
                 *  {
                 *      Console.WriteLine("{0} | {1}: {2}", i, callMsg.GetArgName(i), callMsg.GetArg(i));
                 *  }
                 *  retMsg = RemotingServices.ExecuteMessage(target, callMsg);
                 * }
                 * else
                 * {
                 *  //메소드 실행 코드
                 *  retMsg = RemotingServices.ExecuteMessage(target, callMsg);
                 * }
                 */
                retMsg = RemotingServices.ExecuteMessage(target, callMsg);
            }

            if (retMsg.Exception != null)
            {
                Console.WriteLine(retMsg.MethodName + " 에서 " + retMsg.Exception.Message);
                //Environment.Exit(0);
            }

            // 메소드 종료 로그
            if (fLog)
            {
                MethodLeaveLog(retMsg);
            }

            return(retMsg);
        }
Exemplo n.º 29
0
 public StackBuilderSink(MarshalByRefObject obj, bool forceInternalExecute)
 {
     _target = obj;
     if (!forceInternalExecute && RemotingServices.IsTransparentProxy(obj))
     {
         _rp = RemotingServices.GetRealProxy(obj);
     }
 }
Exemplo n.º 30
0
        public TEntity GenEntityProxy <TEntity>()
        {
            RealProxy <TEntity> realProxy = new RealProxy <TEntity>();

            realProxy.GetPropertyEvent += new GetPropertyDelegate((methodInfo, propertyName) => this[propertyName].ToObject(methodInfo.ReturnType));
            realProxy.SetPropertyEvent += new SetPropertyDelegate((methodInfo, propertyName, value) => this[propertyName] = (value == null) ? null : value.ToString());
            return(realProxy.Entity);
        }
 // Methods
 public static void SetStubData(RealProxy rp, object stubData)
 {
 }
 public static object GetStubData(RealProxy rp)
 {
 }