예제 #1
0
        public override RealProxy CreateProxy(ObjRef objRef,
                                              Type serverType,
                                              Object serverObject,
                                              Context serverContext)

        {
            DBG.Assert(serverType != null, "server type is null in CreateProxy");

            //
            // If this guy isn't one of our objrefs, then we should use remoting.  Otherwise,
            // go ahead and call GetRealObject on it.
            //
            if (objRef == null)
            {
                return(base.CreateProxy(objRef, serverType, serverObject, serverContext));
            }

            if ((objRef is FastRSCPObjRef) ||
                ((objRef is ServicedComponentMarshaler) &&
                 (!objRef.IsFromThisProcess() || ServicedComponentInfo.IsTypeEventSource(serverType))))
            {
                DBG.Info(DBG.SC, "SCPA: CreateProxy: delegating custom CreateProxy");
                Object otp = objRef.GetRealObject(new StreamingContext(StreamingContextStates.Remoting));
                return(RemotingServices.GetRealProxy(otp));
            }
            else
            {
                DBG.Info(DBG.SC, "SCPA: CreateProxy: delegating standard CreateProxy");
                return(base.CreateProxy(objRef, serverType, serverObject, serverContext));
            }
        }
예제 #2
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());
                }
            }
        }
 internal RemoteServicedComponentProxy(Type serverType, IntPtr pUnk, bool fAttachServer) : base(serverType)
 {
     this._fUseIntfDispatch = ServicedComponentInfo.IsTypeEventSource(serverType) || ServicedComponentInfo.AreMethodsSecure(serverType);
     if (pUnk != IntPtr.Zero)
     {
         this._pUnk   = pUnk;
         this._server = EnterpriseServicesHelper.WrapIUnknownWithComObject(pUnk);
         if (fAttachServer)
         {
             base.AttachServer((MarshalByRefObject)this._server);
             this._fAttachedServer = true;
         }
     }
 }
 public override object GetRealObject(StreamingContext context)
 {
     if (!this.IsMarshaledObject)
     {
         return(this);
     }
     if (base.IsFromThisProcess() && !ServicedComponentInfo.IsTypeEventSource(this._rt))
     {
         object realObject = base.GetRealObject(context);
         ((ServicedComponent)realObject).DoSetCOMIUnknown(IntPtr.Zero);
         return(realObject);
     }
     if (this._rp == null)
     {
         this._rp = this._um.GetRealProxy();
     }
     return(this._rp.GetTransparentProxy());
 }
예제 #5
0
        internal RemoteServicedComponentProxy(Type serverType, IntPtr pUnk, bool fAttachServer)
            : base(serverType)
        {
            DBG.Info(DBG.SC, "RSCP: type = " + serverType);
            DBG.Assert(serverType != null, "server type is null");

            _fUseIntfDispatch = (ServicedComponentInfo.IsTypeEventSource(serverType) ||
                                 ServicedComponentInfo.AreMethodsSecure(serverType));
            DBG.Info(DBG.SC, "RSCP: using interface dispatch = " + _fUseIntfDispatch);
            if (pUnk != IntPtr.Zero)
            {
                _pUnk   = pUnk;
                _server = EnterpriseServicesHelper.WrapIUnknownWithComObject(pUnk);
                if (fAttachServer)
                {
                    AttachServer((MarshalByRefObject)_server);
                    _fAttachedServer = true;
                }
            }
        }
예제 #6
0
        public override MarshalByRefObject CreateInstance(Type serverType)
        {
            // Platform.Assert(Platform.W2K, "ServicedComponent");

            RealProxy          rp = null;
            MarshalByRefObject mo = null;

            DBG.Info(DBG.SC, "SCPA.CreateInstance(" + serverType + ") for managed request");


            ServicedComponentProxy.CleanupQueues(true);

            // First check if the type is configured to be activated remotely or is a well
            // known remote type.
            if ((null != RemotingConfiguration.IsWellKnownClientType(serverType)) ||
                (null != RemotingConfiguration.IsRemotelyActivatedClientType(serverType)))
            {
                // It is configured for remote activation. Ask remoting services to do the
                // job of creating a remoting proxy and returning it.
                mo = base.CreateInstance(serverType);
                rp = RemotingServices.GetRealProxy(mo);
            }
            else
            {
                bool   bIsAnotherProcess = false;
                string uri         = "";
                bool   bEventClass = ServicedComponentInfo.IsTypeEventSource(serverType);
                IntPtr pUnk        = Thunk.Proxy.CoCreateObject(serverType, !bEventClass, ref bIsAnotherProcess, ref uri);
                if (pUnk != IntPtr.Zero)
                {
                    try {
                        // TODO:  Get rid of this useless foreknowledge requirement
                        // Is there a way we can tell by QI'ing this guy if he's
                        // an event class (or something else we need to artificially
                        // wrap?
                        if (bEventClass)
                        {
                            // events and queued components use RemoteServicedComponentProxy
                            // set up a TP & Remote ServicedComponentProxy pair
                            rp = new RemoteServicedComponentProxy(serverType, pUnk, true);
                            mo = (MarshalByRefObject)rp.GetTransparentProxy();
                        }
                        else
                        {
                            if (bIsAnotherProcess)              // a-ha, we know it should be a RSCP now !!!!
                            {
                                FastRSCPObjRef oref = new FastRSCPObjRef(pUnk, serverType, uri);
                                mo = (MarshalByRefObject)RemotingServices.Unmarshal(oref);

                                DBG.Assert(mo != null, "RemotingServices.Unmarshal returned null!");
                                DBG.Assert(RemotingServices.GetRealProxy(mo) is RemoteServicedComponentProxy, "RemotingServices.Unmarshal did not return an RSCP!");
                            }
                            else        // bummer, this will give us back a SCP
                            {
                                mo = (MarshalByRefObject)Marshal.GetObjectForIUnknown(pUnk);

                                DBG.Info(DBG.SC, "ret = " + mo.GetType());
                                DBG.Info(DBG.SC, "st = " + serverType);
                                DBG.Info(DBG.SC, "rt == sc = " + (mo.GetType() == serverType));
                                DBG.Info(DBG.SC, "instanceof = " + serverType.IsInstanceOfType(mo));

                                if (!(serverType.IsInstanceOfType(mo)))
                                {
                                    throw new InvalidCastException(Resource.FormatString("ServicedComponentException_UnexpectedType", serverType, mo.GetType()));
                                }

                                rp = RemotingServices.GetRealProxy(mo);
                                if (!(rp is ServicedComponentProxy) && !(rp is RemoteServicedComponentProxy))
                                {
                                    // in cross-appdomain scenario, we get back a RemotingProxy, SetCOMIUnknown has not been made on our server!
                                    ServicedComponent sc = (ServicedComponent)mo;
                                    sc.DoSetCOMIUnknown(pUnk);
                                }
                            }
                        }
                    }
                    finally
                    {
                        Marshal.Release(pUnk);
                    }
                }
            }

            if (rp is ServicedComponentProxy)
            {
                // Here, we tell the server proxy that it needs to filter out
                // constructor calls:  We only need to do this if
                // the proxy lives in the same context as the caller,
                // otherwise we'll get an Invoke call and can do the
                // filtering automagically:
                ServicedComponentProxy scp = (ServicedComponentProxy)rp;
                if (scp.HomeToken == Thunk.Proxy.GetCurrentContextToken())
                {
                    scp.FilterConstructors();
                }
            }

            DBG.Assert(mo is ServicedComponent, " CoCI returned an invalid object type");
            DBG.Info(DBG.SC, "SCPA.CreateInstance done.");
            return(mo);
        }
예제 #7
0
        protected ServicedComponentMarshaler(SerializationInfo info, StreamingContext context)
            : base(info, context)
        {
            byte[] buffer              = null;
            Type   servertype          = null;
            bool   bFoundFIsMarshalled = false;

            DBG.Info(DBG.SC, "SCM: construct");
            ComponentServices.InitializeRemotingChannels();
            SerializationInfoEnumerator e = info.GetEnumerator();

            while (e.MoveNext())
            {
                DBG.Info(DBG.SC, "SCM: ctor: name = " + e.Name + " value = " + e.Value);
                if (e.Name.Equals("servertype"))
                {
                    servertype = (Type)e.Value;
                }
                else if (e.Name.Equals("dcomInfo"))
                {
                    buffer = (byte[])e.Value;
                }
                else if (e.Name.Equals("fIsMarshalled"))
                {
                    int    value = 0;
                    Object o     = e.Value;
                    if (o.GetType() == typeof(String))
                    {
                        value = ((IConvertible)o).ToInt32(null);
                    }
                    else
                    {
                        value = (int)o;
                    }

                    if (value == 0)
                    {
                        bFoundFIsMarshalled = true;
                    }
                }
            }

            if (!bFoundFIsMarshalled)
            {
                DBG.Info(DBG.SC, "SCM: ctor: didn't find fIsMarshalled.");
                _marshalled = true;
            }

            _um = new SCUnMarshaler(servertype, buffer);

            _rt = servertype;


            if (IsFromThisProcess() && !ServicedComponentInfo.IsTypeEventSource(servertype))
            {
                _rp = RemotingServices.GetRealProxy(base.GetRealObject(context));
            }
            else
            {
                DBG.Assert(servertype != null, "SCM: server type is null during marshal.");
                if (ServicedComponentInfo.IsTypeEventSource(servertype))
                {
                    TypeInfo = (IRemotingTypeInfo) new SCMTypeName(servertype);
                }
                Object otp = base.GetRealObject(context);
                _rp = RemotingServices.GetRealProxy(otp);
            }
            // cleanup the buffer, in case we found an existing rp
            _um.Dispose();
        }
        protected ServicedComponentMarshaler(SerializationInfo info, StreamingContext context) : base(info, context)
        {
            byte[] buffer = null;
            Type   type   = null;
            bool   flag   = false;

            ComponentServices.InitializeRemotingChannels();
            SerializationInfoEnumerator enumerator = info.GetEnumerator();

            while (enumerator.MoveNext())
            {
                if (enumerator.Name.Equals("servertype"))
                {
                    type = (Type)enumerator.Value;
                }
                else
                {
                    if (enumerator.Name.Equals("dcomInfo"))
                    {
                        buffer = (byte[])enumerator.Value;
                        continue;
                    }
                    if (enumerator.Name.Equals("fIsMarshalled"))
                    {
                        int    num  = 0;
                        object obj2 = enumerator.Value;
                        if (obj2.GetType() == typeof(string))
                        {
                            num = ((IConvertible)obj2).ToInt32(null);
                        }
                        else
                        {
                            num = (int)obj2;
                        }
                        if (num == 0)
                        {
                            flag = true;
                        }
                    }
                }
            }
            if (!flag)
            {
                this._marshalled = true;
            }
            this._um = new SCUnMarshaler(type, buffer);
            this._rt = type;
            if (base.IsFromThisProcess() && !ServicedComponentInfo.IsTypeEventSource(type))
            {
                this._rp = RemotingServices.GetRealProxy(base.GetRealObject(context));
            }
            else
            {
                if (ServicedComponentInfo.IsTypeEventSource(type))
                {
                    this.TypeInfo = new SCMTypeName(type);
                }
                object realObject = base.GetRealObject(context);
                this._rp = RemotingServices.GetRealProxy(realObject);
            }
            this._um.Dispose();
        }
 public override RealProxy CreateProxy(ObjRef objRef, Type serverType, object serverObject, Context serverContext)
 {
     if (objRef == null)
     {
         return(base.CreateProxy(objRef, serverType, serverObject, serverContext));
     }
     if (!(objRef is FastRSCPObjRef) && (!(objRef is ServicedComponentMarshaler) || (objRef.IsFromThisProcess() && !ServicedComponentInfo.IsTypeEventSource(serverType))))
     {
         return(base.CreateProxy(objRef, serverType, serverObject, serverContext));
     }
     return(RemotingServices.GetRealProxy(objRef.GetRealObject(new StreamingContext(StreamingContextStates.Remoting))));
 }
        public override MarshalByRefObject CreateInstance(Type serverType)
        {
            RealProxy          realProxy        = null;
            MarshalByRefObject transparentProxy = null;

            ServicedComponentProxy.CleanupQueues(false);
            if ((RemotingConfiguration.IsWellKnownClientType(serverType) != null) || (RemotingConfiguration.IsRemotelyActivatedClientType(serverType) != null))
            {
                transparentProxy = base.CreateInstance(serverType);
                realProxy        = RemotingServices.GetRealProxy(transparentProxy);
            }
            else
            {
                bool   bIsAnotherProcess = false;
                string uri   = "";
                bool   flag2 = ServicedComponentInfo.IsTypeEventSource(serverType);
                IntPtr pUnk  = Proxy.CoCreateObject(serverType, !flag2, ref bIsAnotherProcess, ref uri);
                if (pUnk != IntPtr.Zero)
                {
                    try
                    {
                        if (flag2)
                        {
                            realProxy        = new RemoteServicedComponentProxy(serverType, pUnk, true);
                            transparentProxy = (MarshalByRefObject)realProxy.GetTransparentProxy();
                        }
                        else
                        {
                            bool flag3 = (RemotingConfiguration.IsWellKnownClientType(serverType) != null) || (null != RemotingConfiguration.IsRemotelyActivatedClientType(serverType));
                            if (bIsAnotherProcess && !flag3)
                            {
                                FastRSCPObjRef objectRef = new FastRSCPObjRef(pUnk, serverType, uri);
                                transparentProxy = (MarshalByRefObject)RemotingServices.Unmarshal(objectRef);
                            }
                            else
                            {
                                transparentProxy = (MarshalByRefObject)Marshal.GetObjectForIUnknown(pUnk);
                                if (!serverType.IsInstanceOfType(transparentProxy))
                                {
                                    throw new InvalidCastException(Resource.FormatString("ServicedComponentException_UnexpectedType", serverType, transparentProxy.GetType()));
                                }
                                realProxy = RemotingServices.GetRealProxy(transparentProxy);
                                if ((!bIsAnotherProcess && !(realProxy is ServicedComponentProxy)) && !(realProxy is RemoteServicedComponentProxy))
                                {
                                    ((ServicedComponent)transparentProxy).DoSetCOMIUnknown(pUnk);
                                }
                            }
                        }
                    }
                    finally
                    {
                        Marshal.Release(pUnk);
                    }
                }
            }
            if (realProxy is ServicedComponentProxy)
            {
                ServicedComponentProxy proxy2 = (ServicedComponentProxy)realProxy;
                if (proxy2.HomeToken == Proxy.GetCurrentContextToken())
                {
                    proxy2.FilterConstructors();
                }
            }
            return(transparentProxy);
        }