コード例 #1
0
        public override void GetObjectData(SerializationInfo info, StreamingContext context)
        {
            ComponentServices.InitializeRemotingChannels();
            if (info == null)
            {
                throw new ArgumentNullException("info");
            }
            object data = CallContext.GetData("__ClientIsClr");

            if ((data != null) && ((bool)data))
            {
                RemoteServicedComponentProxy proxy = this._rp as RemoteServicedComponentProxy;
                if (proxy != null)
                {
                    RemotingServices.Marshal((MarshalByRefObject)proxy.RemotingIntermediary.GetTransparentProxy(), null, null).GetObjectData(info, context);
                }
                else
                {
                    base.GetObjectData(info, context);
                }
            }
            else
            {
                base.GetObjectData(info, context);
                info.SetType(typeof(ServicedComponentMarshaler));
                info.AddValue("servertype", this._rp.GetProxiedType());
                byte[] dCOMBuffer = ComponentServices.GetDCOMBuffer((MarshalByRefObject)this._rp.GetTransparentProxy());
                if (dCOMBuffer != null)
                {
                    info.AddValue("dcomInfo", dCOMBuffer);
                }
            }
        }
コード例 #2
0
 public void GetObjectData(object obj, SerializationInfo info, StreamingContext ctx)
 {
     if (!obj.GetType().IsCOMObject)
     {
         throw new NotSupportedException();
     }
     info.SetType(typeof(ComObjRef));
     info.AddValue("buffer", ComponentServices.GetDCOMBuffer(obj));
 }
コード例 #3
0
        void IObjectControl.Deactivate()
        {
            ServicedComponentProxy target = (ServicedComponentProxy)this._scp.Target;

            if (target != null)
            {
                ComponentServices.DeactivateObject(target.GetTransparentProxy(), true);
            }
        }
コード例 #4
0
        // copied from ServicedComponentMarshaler above directly
        // IF YOU MAK ANY CHANGES TO THIS, KEEP THE OTHER COPY IN SYNC
        public override void GetObjectData(SerializationInfo info, StreamingContext context)
        {
            DBG.Info(DBG.SC, "FSCM: GetObjectData");
            ComponentServices.InitializeRemotingChannels();
            if (info == null)
            {
                throw new ArgumentNullException("info");
            }

            // Check to see if this is a remoting channel, if so, then we
            // should use the standard objref marshal (cause we're going over SOAP
            // or another remoting channel).
            object oClientIsClr = CallContext.GetData("__ClientIsClr");

            DBG.Info(DBG.SC, "FSCM: GetObjectData: oClientIsClr = " + oClientIsClr);
            bool bUseStandardObjRef = (oClientIsClr == null)?false:(bool)oClientIsClr;

            if (bUseStandardObjRef)
            {
                RemoteServicedComponentProxy rscp = _rp as RemoteServicedComponentProxy;
                if (rscp != null)
                {
                    DBG.Info(DBG.SC, "FSCM: GetObjectData: intermediary objref");
                    ObjRef std = RemotingServices.Marshal((MarshalByRefObject)(rscp.RemotingIntermediary.GetTransparentProxy()), null, null);
                    std.GetObjectData(info, context);
                }
                else
                {
                    DBG.Info(DBG.SC, "FSCM: GetObjectData: Using standard objref");
                    base.GetObjectData(info, context);
                }
            }
            else
            {
                DBG.Info(DBG.SC, "FSCM: GetObjectData: Using custom objref");
                base.GetObjectData(info, context);

                //*** base.GetObjectData sets the type to be itself
                // now wack the type to be us
                info.SetType(typeof(ServicedComponentMarshaler));

                DBG.Assert(_rp != null, "_rp is null");

                info.AddValue("servertype", _rp.GetProxiedType());

                byte[] dcomBuffer = ComponentServices.GetDCOMBuffer((MarshalByRefObject)_rp.GetTransparentProxy());

                DBG.Assert(dcomBuffer != null, "dcomBuffer is null");

                if (dcomBuffer != null)
                {
                    info.AddValue("dcomInfo", dcomBuffer);
                }
            }
        }
コード例 #5
0
        private string RemoteDispatchHelper(string s, out bool failed)
        {
            if (this._denyRemoteDispatch)
            {
                throw new UnauthorizedAccessException(Resource.FormatString("ServicedComponentException_SecurityMapping"));
            }
            IMessage request = ComponentServices.ConvertToMessage(s, this);

            this.CheckMethodAccess(request);
            IMessage             reqMsg   = RemotingServices.GetRealProxy(this).Invoke(request);
            IMethodReturnMessage message3 = reqMsg as IMethodReturnMessage;

            if ((message3 != null) && (message3.Exception != null))
            {
                failed = true;
            }
            else
            {
                failed = false;
            }
            return(ComponentServices.ConvertToString(reqMsg));
        }
コード例 #6
0
        // helper to implement RemoteDispatch methods
        private String RemoteDispatchHelper(String s, out bool failed)
        {
            if (_denyRemoteDispatch)
            {
                throw new UnauthorizedAccessException(Resource.FormatString("ServicedComponentException_SecurityMapping"));
            }
            IMessage reqMsg = ComponentServices.ConvertToMessage(s, this);


            // Check to see if the method is marked as secure on the
            // server side:  If so, we need to kick it back to the caller,
            // cause they called us incorrectly.  Also verify the method
            // is not private, internal, or static.

            CheckMethodAccess(reqMsg);

            RealProxy rp = RemotingServices.GetRealProxy(this);

            DBG.Assert(rp != null, "Null RP in Invoke helper");

            IMessage retMsg = rp.Invoke(reqMsg);

            // Check for failures:
            IMethodReturnMessage mrm = retMsg as IMethodReturnMessage;

            if (mrm != null && mrm.Exception != null)
            {
                failed = true;
            }
            else
            {
                failed = false;
            }

            String sret = ComponentServices.ConvertToString(retMsg);

            return(sret);
        }
コード例 #7
0
 void IObjectControl.Deactivate()
 {
     ComponentServices.DeactivateObject(this._scp.GetTransparentProxy(), true);
 }
コード例 #8
0
        // Implement Invoke
        public override IMessage Invoke(IMessage reqMsg)
        {
            AssertValid();
            IMessage retMsg = null;

            // CHECK FOR CTOR
            if (reqMsg is IConstructionCallMessage)
            {
                DBG.Info(DBG.SC, "RSCP: Short circuiting constructor call.");

                if (((IConstructionCallMessage)reqMsg).ArgCount > 0)
                {
                    throw new ServicedComponentException(Resource.FormatString("ServicedComponentException_ConstructorArguments"));
                }

                // WE don't need dispatch the constructor message, the default .ctor is called
                // by CoCI
                // Create the return message
                MarshalByRefObject retObj = (MarshalByRefObject)GetTransparentProxy();
                return(EnterpriseServicesHelper.CreateConstructionReturnMessage((IConstructionCallMessage)reqMsg, retObj));
            }

            // NON CTOR MESSAGE
            MethodBase mb = ((IMethodMessage)reqMsg).MethodBase;
            MemberInfo m  = (MemberInfo)mb;

            DBG.Assert(m != null, "member info should not be null");

            if (mb == _getTypeMethod)
            {
                DBG.Info(DBG.SC, "RSCP: Hijacking call to GetType");
                IMethodCallMessage mcm = (IMethodCallMessage)reqMsg;
                return(new ReturnMessage(ProxiedType, null, 0, mcm.LogicalCallContext, mcm));
            }

            if (mb == _getHashCodeMethod)
            {
                int hashCode = this.GetHashCode();
                DBG.Info(DBG.SC, "RSCP: Hijacking call to GetHashCode, returning " + hashCode);
                IMethodCallMessage mcm = (IMethodCallMessage)reqMsg;
                return(new ReturnMessage(hashCode, null, 0, mcm.LogicalCallContext, mcm));
            }

            DBG.Info(DBG.SC, "RSCP: Delivering call to " + mb.Name);

            // convert to class member info
            MemberInfo clsMemInfo = ReflectionCache.ConvertToClassMI(ProxiedType, m);

            DBG.Assert(!clsMemInfo.ReflectedType.IsInterface,
                       "Failed to convert interface member info to class member info");

            // dispatch the call
#if _DEBUG
            if (clsMemInfo != m)
            {
                DBG.Info(DBG.SC, "RSCP: converted interface to class call: " + clsMemInfo.Name);
            }
#endif

            try
            {
                int iMethodInfo;
                // check for rolebased security
                if (_fUseIntfDispatch ||
                    (((iMethodInfo = ServicedComponentInfo.MICachedLookup(clsMemInfo)) & ServicedComponentInfo.MI_HASSPECIALATTRIBUTES) != 0) ||
                    ((iMethodInfo & ServicedComponentInfo.MI_EXECUTEMESSAGEVALID) != 0)
                    )
                {
                    // role based security implies we dispatch through an interface
                    MemberInfo intfMemInfo = ReflectionCache.ConvertToInterfaceMI(m);
                    if (intfMemInfo == null)
                    {
                        throw new ServicedComponentException(Resource.FormatString("ServicedComponentException_SecurityMapping"));
                    }
                    //retMsg = EnterpriseServicesHelper.DispatchRemoteCall(reqMsg, intfMemInfo, _server);
                    MethodCallMessageWrapperEx msgex = new MethodCallMessageWrapperEx((IMethodCallMessage)reqMsg, (MethodBase)intfMemInfo);
                    retMsg = RemotingServices.ExecuteMessage((MarshalByRefObject)_server, (IMethodCallMessage)msgex);
                }
                else
                {
                    // check for AutoDone
                    bool fAutoDone = (iMethodInfo & ServicedComponentInfo.MI_AUTODONE) != 0;

                    String s = ComponentServices.ConvertToString(reqMsg);

                    IRemoteDispatch iremDisp = (IRemoteDispatch)_server;

                    String sret;
                    if (fAutoDone)
                    {
                        sret = iremDisp.RemoteDispatchAutoDone(s);
                    }
                    else
                    {
                        sret = iremDisp.RemoteDispatchNotAutoDone(s);
                    }
                    retMsg = ComponentServices.ConvertToReturnMessage(sret, reqMsg);
                }
            }
            catch (COMException e)
            {
                if (!(e.ErrorCode == Util.CONTEXT_E_ABORTED || e.ErrorCode == Util.CONTEXT_E_ABORTING))
                {
                    throw;
                }
                if (IsDisposeRequest(reqMsg))
                {
                    IMethodCallMessage mcm = reqMsg as IMethodCallMessage;
                    retMsg = new ReturnMessage(null, null, 0, mcm.LogicalCallContext, mcm);
                }
                else
                {
                    throw;
                }
            }

            // if disposing, we need to release this side of the world.
            if (IsDisposeRequest(reqMsg))
            {
                Dispose(true);
            }

            return(retMsg);
        }
コード例 #9
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();
        }
        public override IMessage Invoke(IMessage reqMsg)
        {
            this.AssertValid();
            IMessage message = null;

            if (reqMsg is IConstructionCallMessage)
            {
                if (((IConstructionCallMessage)reqMsg).ArgCount > 0)
                {
                    throw new ServicedComponentException(Resource.FormatString("ServicedComponentException_ConstructorArguments"));
                }
                MarshalByRefObject transparentProxy = (MarshalByRefObject)this.GetTransparentProxy();
                return(EnterpriseServicesHelper.CreateConstructionReturnMessage((IConstructionCallMessage)reqMsg, transparentProxy));
            }
            MethodBase methodBase = ((IMethodMessage)reqMsg).MethodBase;
            MemberInfo mi         = methodBase;

            if (methodBase == _getTypeMethod)
            {
                IMethodCallMessage mcm = (IMethodCallMessage)reqMsg;
                return(new ReturnMessage(this.ProxiedType, null, 0, mcm.LogicalCallContext, mcm));
            }
            if (methodBase == _getHashCodeMethod)
            {
                int hashCode = this.GetHashCode();
                IMethodCallMessage message3 = (IMethodCallMessage)reqMsg;
                return(new ReturnMessage(hashCode, null, 0, message3.LogicalCallContext, message3));
            }
            if (methodBase == _isInstanceOfTypeMethod)
            {
                IMethodCallMessage message4 = (IMethodCallMessage)reqMsg;
                Type inArg = (Type)message4.GetInArg(0);
                return(new ReturnMessage(inArg.IsInstanceOfType(this.ProxiedType), null, 0, message4.LogicalCallContext, message4));
            }
            MemberInfo m = ReflectionCache.ConvertToClassMI(this.ProxiedType, mi);

            try
            {
                int num2;
                if ((this._fUseIntfDispatch || (((num2 = ServicedComponentInfo.MICachedLookup(m)) & 4) != 0)) || ((num2 & 8) != 0))
                {
                    MemberInfo info3 = ReflectionCache.ConvertToInterfaceMI(mi);
                    if (info3 == null)
                    {
                        throw new ServicedComponentException(Resource.FormatString("ServicedComponentException_SecurityMapping"));
                    }
                    MethodCallMessageWrapperEx ex = new MethodCallMessageWrapperEx((IMethodCallMessage)reqMsg, (MethodBase)info3);
                    message = RemotingServices.ExecuteMessage((MarshalByRefObject)this._server, ex);
                }
                else
                {
                    string          str2;
                    bool            flag     = (num2 & 2) != 0;
                    string          s        = ComponentServices.ConvertToString(reqMsg);
                    IRemoteDispatch dispatch = (IRemoteDispatch)this._server;
                    if (flag)
                    {
                        str2 = dispatch.RemoteDispatchAutoDone(s);
                    }
                    else
                    {
                        str2 = dispatch.RemoteDispatchNotAutoDone(s);
                    }
                    message = ComponentServices.ConvertToReturnMessage(str2, reqMsg);
                }
            }
            catch (COMException exception)
            {
                if ((exception.ErrorCode != -2147164158) && (exception.ErrorCode != -2147164157))
                {
                    throw;
                }
                if (!this.IsDisposeRequest(reqMsg))
                {
                    throw;
                }
                IMethodCallMessage message5 = reqMsg as IMethodCallMessage;
                message = new ReturnMessage(null, null, 0, message5.LogicalCallContext, message5);
            }
            if (this.IsDisposeRequest(reqMsg))
            {
                this.Dispose(true);
            }
            return(message);
        }
コード例 #11
0
        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();
        }
コード例 #12
0
 internal void _internalDeactivate(bool disposing)
 {
     ComponentServices.DeactivateObject(this, disposing);
 }