Наследование: IObjectReference, ISerializable
Пример #1
1
 /// <summary>
 /// Initializes a new instance of the <see cref="RemoteServer"/> class.
 /// </summary>
 public RemoteServer()
 {
     RemoteObj = new RemoteObject();
     serverchannel = new IpcChannel("localhost:15000");
     ChannelServices.RegisterChannel(serverchannel, false);
     ref1 = RemotingServices.Marshal(RemoteObj, "RemoteObject.rem");
     Console.WriteLine("ObjRef1 URI: " + ref1.URI);
     RemoteObj.ObjectSent += new ObjectSentEventHandler(OnObjectSent);
 }
Пример #2
0
		public MockServer(MarshalByRefObject mock, IChannel channel, string uri)
		{
			this.mock = mock;
			this.channel = channel;
			ChannelServices.RegisterChannel(channel, true);
			mockRef = RemotingServices.Marshal(mock, uri);
		}
Пример #3
0
        public JobManagerFixture()
        {
            BinaryServerFormatterSinkProvider serverProv = new BinaryServerFormatterSinkProvider();
            serverProv.TypeFilterLevel = System.Runtime.Serialization.Formatters.TypeFilterLevel.Full;

            System.Collections.IDictionary ClientTcpChannelProperties = new System.Collections.Hashtable();
            ClientTcpChannelProperties["name"] = "ClientTcpChan";
            ChannelServices.RegisterChannel(
                    new System.Runtime.Remoting.Channels.Tcp.TcpClientChannel(ClientTcpChannelProperties, new BinaryClientFormatterSinkProvider()), false);

            int port = 35010;

            System.Collections.IDictionary TcpChannelProperties = new System.Collections.Hashtable();
            TcpChannelProperties["port"] = port;
            try
            {
                chan = new System.Runtime.Remoting.Channels.Tcp.TcpServerChannel(TcpChannelProperties, serverProv);
                ChannelServices.RegisterChannel(chan, false);
                server = new JobServerImpl();
                serverRef = RemotingServices.Marshal(server, "JobServer");
                server.handlersAdded.Set();
            }
            catch (SocketException e)
            {
                if (!e.Message.StartsWith("Only one usage of each socket address"))
                {
                    throw;
                }
            }
        }
Пример #4
0
		public void UnmarshaledObject(
			object obj,
			ObjRef or
			)
		{
			Console.WriteLine(AppDomain.CurrentDomain.FriendlyName+" Unmarshaled: "+obj.GetType().FullName);
		}
		/// <summary>
		/// Initializes a new instance of the InstanceManager class.
		/// </summary>
		public InstanceManager(int port, string mutexName)
			: base()
		{
			try
			{
				_port = port;
				_mutexName = mutexName.Replace("-", null);
				string executablePath = this.ExecutablePath;
				_url = string.Format("tcp://127.0.0.1:{0}/{1}", port.ToString(), executablePath);
				_instance = new Mutex(false, mutexName);

				// if this is the only instance then register a new channel on the specified port
				// and marshall this object instance on the channel
				if (this.IsOnlyInstance)
				{
					// create a tcp channel
					_channel = new TcpChannel(port);

					// register it
					ChannelServices.RegisterChannel(_channel, false);

					// marshal the instance manager
					_marshalledObject = RemotingServices.Marshal(this, executablePath);

					Log.WriteLine(_marshalledObject.URI);
				}
			}
			catch (Exception ex)
			{
				Debug.WriteLine(ex);
			}
		}
Пример #6
0
        public RemotingHostServer(Machine machine, int port, string name)
            : base(machine)
        {
            this.port = port;
            this.name = name;

            // TODO review this name, get machine name
            this.hostname = "localhost";

            // According to http://www.thinktecture.com/resourcearchive/net-remoting-faq/changes2003
            // in order to have ObjRef accessible from client code
            BinaryServerFormatterSinkProvider serverProv = new BinaryServerFormatterSinkProvider();
            serverProv.TypeFilterLevel = System.Runtime.Serialization.Formatters.TypeFilterLevel.Full;

            BinaryClientFormatterSinkProvider clientProv = new BinaryClientFormatterSinkProvider();

            IDictionary props = new Hashtable();
            props["port"] = port;

            TcpChannel channel = new TcpChannel(props, clientProv, serverProv);

            if (!registered)
            {
                ChannelServices.RegisterChannel(channel, false);
                registered = true;
            }

            // end of "according"

            // TODO review other options to publish an object
            this.objref = RemotingServices.Marshal(this, name);
        }
Пример #7
0
 // stellt dieses Objekt via Remoting zur Verfügung
 public void InitialisiereRemotableObject()
 {
     // melde dieses Objekt unter der gegebenen URL auf dem spezifierten Pfad an
     _PortalLogikObjRef = RemotingServices.Marshal(
         this,
          this._Pfad,
         ((Object)this).GetType());
 }
Пример #8
0
		internal ObjRef DeserializeInTheCurrentDomain (int domainId, byte[] tInfo)
		{
				string local_uri = string.Copy (this.uri);
				ChannelInfo cinfo = new ChannelInfo (new CrossAppDomainData (domainId));
				ObjRef res = new ObjRef (local_uri, cinfo);
				IRemotingTypeInfo typeInfo = (IRemotingTypeInfo)CADSerializer.DeserializeObjectSafe (tInfo);
				res.typeInfo = typeInfo;
				return res;
		}
Пример #9
0
 // Notifies a handler that an object has been unmarshaled.
 public void UnmarshaledObject(Object obj, ObjRef or)
 {
     if (obj.GetType() != typeof(AppDomain))
         Trace.WriteLine(string.Format("Tangra Addins: Unmarshaled instance of {0} ({1} HashCode:{2})", or.TypeInfo != null ? or.TypeInfo.TypeName : obj.GetType().ToString(), or.URI != null ? or.URI.ToString() : "N/A", obj.GetHashCode().ToString()));
     else
     {
         // Not interested in AppDomain marshalling
     }
 }
Пример #10
0
        public DFSManager(DFServer srv, string id)
        {
            this.server = srv;
            this.id = id;

            server.registerInterface(this);

            objrefWellKnown = RemotingServices.Marshal(this, id);
        }
Пример #11
0
		internal ObjRef (ObjRef o, bool unmarshalAsProxy) {
			channel_info = o.channel_info;
			uri = o.uri;
	
			typeInfo = o.typeInfo;
			envoyInfo = o.envoyInfo;
			flags = o.flags;
			if (unmarshalAsProxy) flags |= MarshalledObjectRef;
		}
 private ObjRef(ObjRef o)
 {
     this.uri = o.uri;
     this.typeInfo = o.typeInfo;
     this.envoyInfo = o.envoyInfo;
     this.channelInfo = o.channelInfo;
     this.objrefFlags = o.objrefFlags;
     this.SetServerIdentity(o.GetServerIdentity());
     this.SetDomainID(o.GetDomainID());
 }
Пример #13
0
        /// <summary>
        /// Parameteraize Constructor.
        /// </summary>
        /// <param name="type"></param>
        /// <param name="target"></param>
        public DiaSoftProxy(Type type, MarshalByRefObject target)
            : base(type)
        {
            _serverType = type;
            BuildTcpURL(RemotingServices.GetObjectUri((MarshalByRefObject)target));
            BuildHttpURL(RemotingServices.GetObjectUri((MarshalByRefObject)target));
            _targetTcp = target;
            _targetHttp = (MarshalByRefObject)Activator.GetObject(type, _HttpUrl);

            objRef = RemotingServices.Marshal(target);
            _messageSinks = GetMessageSinks();
        }
Пример #14
0
 // Notifies a handler that an object has been marshaled.
 public void MarshaledObject(Object obj, ObjRef or)
 {
     if (obj.GetType() != typeof(AppDomain))
     {
         if (TraceSwitchAppDomainTracking.Enabled)
             Trace.WriteLine(string.Format("OccuRec: Marshaled instance of {0} ({1} HashCode:{2})", or.TypeInfo != null ? or.TypeInfo.TypeName : obj.GetType().ToString(), or.URI != null ? or.URI.ToString() : "N/A", obj.GetHashCode().ToString()));
     }
     else
     {
         // Not interested in AppDomain marshalling
     }
 }
Пример #15
0
 public IMessage SyncProcessMessage(IMessage msg)
 {
     IMethodMessage methodMessage = (IMethodMessage)msg;
     if (methodMessage.MethodName == ".ctor")
     {
         IMethodReturnMessage retMsg = (IMethodReturnMessage)this.NextSink.SyncProcessMessage(msg);
         _realObj = (ObjRef)retMsg.ReturnValue;
         return retMsg;
     }
     AOPBaseClass obj = (AOPBaseClass)RemotingServices.Unmarshal(_realObj);
     return obj.SyncProcessMessage(this.NextSink, msg);
 }
Пример #16
0
        public DFSManager(DFServer srv, string id, NamingContext nc)
        {
            this.server = srv;
            this.id = id;

            server.registerInterface(this);

            objrefWellKnown = RemotingServices.Marshal(this, id);

            this.nameService = nc;
            if ( nameService != null ) nameService.rebind(new NameComponent[] { new NameComponent(id) }, this);
        }
Пример #17
0
        public IMessage SyncProcessMessage(IMessage msg)
        {
            IMethodMessage methodMessage = (IMethodMessage)msg;

            if (methodMessage.MethodName == ".ctor") {
                IMethodReturnMessage ret = (IMethodReturnMessage)m_NextSink.SyncProcessMessage(msg);
                realobject = (ObjRef)ret.ReturnValue;
                return ret;
            } else {
                AOPBaseClass obj = (AOPBaseClass)RemotingServices.Unmarshal(realobject);
                return obj.SyncProcessMessage(m_NextSink, msg);
            }
        }
Пример #18
0
		internal static void NotifyMarshaledObject(Object obj, ObjRef or)
		{
			ITrackingHandler[] handlers;
			
			lock (_handlers.SyncRoot) {
				if (_handlers.Count == 0) return;
				handlers = (ITrackingHandler[]) _handlers.ToArray (typeof(ITrackingHandler));
			}
			
			for(int i = 0; i < handlers.Length; i++) {
				handlers[i].MarshaledObject (obj, or);
			}
		}
 internal static void MarshaledObject(object obj, ObjRef or)
 {
     try
     {
         ITrackingHandler[] handlerArray = _Handlers;
         for (int i = 0; i < _Size; i++)
         {
             handlerArray[i].MarshaledObject(obj, or);
         }
     }
     catch
     {
     }
 }
Пример #20
0
        public LogModel(ILog log,ICommandRouter router)
        {
            Hierarchy h = LogManager.GetRepository() as Hierarchy;
            h.Root.AddAppender(this);
            h.Root.Level = Level.Debug;
            this.log = log;
            router.ExceptionExecuting += new EventHandler<ExecutingExceptionEventArgs>(router_ExceptionExecuting);

            channel = new IpcChannel("log4net");

            ChannelServices.RegisterChannel(channel,false);
            oref = RemotingServices.Marshal(this, null);
            ApplicationEnvironment.Instance.LoggerURI = channel.GetUrlsForUri(oref.URI)[0];
        }
Пример #21
0
		/// <summary>
		/// Synchronously processes the given message.
		/// </summary>
		/// <param name="msg">The message to process.</param>
		/// <returns>
		/// A reply message in response to the request.
		/// </returns>
		/// <exception cref="T:System.Security.SecurityException">
		/// The immediate caller makes the call through a reference to the interface and does not have infrastructure permission.
		/// </exception>
		public IMessage SyncProcessMessage(IMessage msg)
		{
			IMethodMessage methodMessage = (IMethodMessage)msg;
			if (methodMessage.MethodName == ".ctor")
			{
				IMethodReturnMessage ret = (IMethodReturnMessage)_nextSink.SyncProcessMessage(msg);
				_realObject = (ObjRef)ret.ReturnValue;
				return ret;
			}
			else
			{
				AspectOrientedObject obj = (AspectOrientedObject)RemotingServices.Unmarshal(_realObject);
				return obj.SyncProcessMessage(_nextSink, msg);
			}
		}
Пример #22
0
 static int CreateObjRef(IntPtr L)
 {
     try
     {
         ToLua.CheckArgsCount(L, 2);
         System.MarshalByRefObject obj = (System.MarshalByRefObject)ToLua.CheckObject(L, 1, typeof(System.MarshalByRefObject));
         System.Type arg0 = (System.Type)ToLua.CheckObject(L, 2, typeof(System.Type));
         System.Runtime.Remoting.ObjRef o = obj.CreateObjRef(arg0);
         ToLua.PushObject(L, o);
         return(1);
     }
     catch (Exception e)
     {
         return(LuaDLL.toluaL_exception(L, e));
     }
 }
		public override RealProxy CreateProxy(ObjRef objRef, Type serverType, Object serverObject, Context serverContext)
		{
			var proxy = new InterceptionRealProxy(serverType);

			if (serverContext != null)
			{
				RealProxy.SetStubData(proxy, serverContext);
			}

			if ((serverType.IsMarshalByRef == false) && (serverContext == null))
			{
				throw new RemotingException("Bad Type for CreateProxy");
			}

			return (proxy);
		}
 public virtual RealProxy CreateProxy(ObjRef objRef, Type serverType, object serverObject, Context serverContext)
 {
     RemotingProxy rp = new RemotingProxy(serverType);
     if (serverContext != null)
     {
         RealProxy.SetStubData(rp, serverContext.InternalContextID);
     }
     if ((objRef != null) && objRef.GetServerIdentity().IsAllocated)
     {
         rp.SetSrvInfo(objRef.GetServerIdentity(), objRef.GetDomainID());
     }
     rp.Initialized = true;
     Type type = serverType;
     if ((!type.IsContextful && !type.IsMarshalByRef) && (serverContext != null))
     {
         throw new RemotingException(Environment.GetResourceString("Remoting_Activation_MBR_ProxyAttribute"));
     }
     return rp;
 }
Пример #25
0
 public IMessage SyncProcessMessage(IMessage msg)
 {
     var method = msg as IMethodMessage;
     if (method.MethodName == ".ctor") {
         var ret = nextSink.SyncProcessMessage(msg) as IMethodReturnMessage;
         realobject = ret.ReturnValue as ObjRef;
         return ret;
     }
     var validators = method.MethodBase.GetCustomAttributes(typeof(ValidationAttribute), false) as ValidationAttribute[];
     if (validators != null) {
         foreach (var validator in validators) {
             validator.MethodMessage = method;
             validator.Validate();
         }
     }
     var bll = RemotingServices.Unmarshal(realobject) as WebBllBase;
     bll.ProcessMessage(msg);
     var retMsg = this.nextSink.SyncProcessMessage(msg);
     return retMsg;
 }
Пример #26
0
 public void MarshaledObject(object obj, ObjRef or)
 {
     Console.WriteLine("--- Marshaled Object " +
     obj.GetType() + " ---");
      Console.WriteLine("Object URI: " + or.URI);
      object[] channelData = or.ChannelInfo.ChannelData;
      foreach (object data in channelData)
      {
     ChannelDataStore dataStore = data as ChannelDataStore;
     if (dataStore != null)
     {
        foreach (string uri in dataStore.ChannelUris)
        {
           Console.WriteLine("Channel URI: " + uri);
        }
     }
      }
      Console.WriteLine("---------");
      Console.WriteLine();
 }
Пример #27
0
 public void MarshaledObject(object obj, ObjRef or)
 {
     object data = CallContext.GetData("ClientIp");
     if ((data != null) && (or.ChannelInfo != null))
     {
         string ip = "";
         string port = "";
         this.SplitClientAddress(data.ToString(), out ip, out port);
         for (int i = or.ChannelInfo.ChannelData.GetLowerBound(0); i <= or.ChannelInfo.ChannelData.GetUpperBound(0); i++)
         {
             if (or.ChannelInfo.ChannelData[i] is ChannelDataStore)
             {
                 foreach (string str3 in ((ChannelDataStore) or.ChannelInfo.ChannelData[i]).ChannelUris)
                 {
                     ChannelDataStore store = new ChannelDataStore(this.GetClientAddressFromUri(str3, ip, port));
                     or.ChannelInfo.ChannelData[i] = store;
                 }
             }
         }
     }
 }
Пример #28
0
        public void StartListen()
        {
            StopListen(); // if there is any channel still open --> close it

            try
            {
                int s32_Port = int.Parse(textBoxPort.Text);

                mi_Channel   = new TcpChannel(s32_Port);
                ChannelServices.RegisterChannel(mi_Channel);

                mi_Transfer  = new Remote.cTransfer();
                mi_Service = RemotingServices.Marshal(mi_Transfer, "TestService");

                // define the event which is triggered when the Client calls the CallServer() function
                mi_Transfer.ev_ServerCall += new Remote.cTransfer.del_ServerCall(OnClientEvent);
            }
            catch (Exception Ex)
            {
                MessageBox.Show(this, "Error starting listening:\n" + Ex.Message, "Server");
                checkBoxListen.Checked = false; // calls StopListen()
            }
        }
Пример #29
0
        public static Object Unmarshal(ObjRef objectRef, bool fRefine)
        {
            Contract.Requires(objectRef != null);

            return(default(Object));
        }
 public void UnmarshaledObject(object obj, System.Runtime.Remoting.ObjRef or)
 {
     Console.WriteLine("UnmarshaledObject: " + obj);
 }
Пример #31
0
 public ClientIdentity(string objectUri, ObjRef objRef) : base(objectUri)
 {
     _objRef    = objRef;
     _envoySink = (_objRef.EnvoyInfo != null) ? _objRef.EnvoyInfo.EnvoySinks : null;
 }
Пример #32
0
        internal void Init(object o, Identity idObj, RuntimeType requestedType)
        {
            this.uri = idObj.URI;
            MarshalByRefObject tpOrObject   = idObj.TPOrObject;
            RuntimeType        runtimeType1 = RemotingServices.IsTransparentProxy((object)tpOrObject) ? (RuntimeType)RemotingServices.GetRealProxy((object)tpOrObject).GetProxiedType() : (RuntimeType)tpOrObject.GetType();
            RuntimeType        runtimeType2 = (RuntimeType)null == requestedType ? runtimeType1 : requestedType;

            if ((RuntimeType)null != requestedType && !requestedType.IsAssignableFrom((System.Reflection.TypeInfo)runtimeType1) && !typeof(IMessageSink).IsAssignableFrom((Type)runtimeType1))
            {
                throw new RemotingException(string.Format((IFormatProvider)CultureInfo.CurrentCulture, Environment.GetResourceString("Remoting_InvalidRequestedType"), (object)requestedType.ToString()));
            }
            this.TypeInfo = !runtimeType1.IsCOMObject ? (IRemotingTypeInfo)InternalRemotingServices.GetReflectionCachedData(runtimeType2).TypeInfo : (IRemotingTypeInfo) new DynamicTypeInfo(runtimeType2);
            if (!idObj.IsWellKnown())
            {
                this.EnvoyInfo = System.Runtime.Remoting.EnvoyInfo.CreateEnvoyInfo(idObj as ServerIdentity);
                IChannelInfo channelInfo = (IChannelInfo) new System.Runtime.Remoting.ChannelInfo();
                if (o is AppDomain)
                {
                    object[] channelData = channelInfo.ChannelData;
                    int      length1     = channelData.Length;
                    object[] objArray1   = new object[length1];
                    object[] objArray2   = objArray1;
                    int      length2     = length1;
                    Array.Copy((Array)channelData, (Array)objArray2, length2);
                    for (int index = 0; index < length1; ++index)
                    {
                        if (!(objArray1[index] is CrossAppDomainData))
                        {
                            objArray1[index] = (object)null;
                        }
                    }
                    channelInfo.ChannelData = objArray1;
                }
                this.ChannelInfo = channelInfo;
                if (runtimeType1.HasProxyAttribute)
                {
                    this.SetHasProxyAttribute();
                }
            }
            else
            {
                this.SetWellKnown();
            }
            if (!ObjRef.ShouldUseUrlObjRef())
            {
                return;
            }
            if (this.IsWellKnown())
            {
                this.SetObjRefLite();
            }
            else
            {
                string httpUrlForObject = ChannelServices.FindFirstHttpUrlForObject(this.URI);
                if (httpUrlForObject == null)
                {
                    return;
                }
                this.URI = httpUrlForObject;
                this.SetObjRefLite();
            }
        }
        /// <summary>Starts the IPC server for the Integration Test service.</summary>
        private void StartServiceCallback(object sender, EventArgs e)
        {
            if (_startServiceMenuCmd.Enabled)
            {
                _service = new IntegrationService();
                _serviceChannel = new IpcServerChannel(null, DefaultPortName, DefaultSinkProvider);

                var serviceType = typeof(IntegrationService);
                _marshalledService = RemotingServices.Marshal(_service, serviceType.FullName, serviceType);

                _serviceChannel.StartListening(null);

                SwapAvailableCommands(_startServiceMenuCmd, _stopServiceMenuCmd);
            }
        }
        //
        //
        // This is typically called when we are unmarshaling an objectref
        // in order to create a client side identity for a remote server
        // object.
        internal static Identity FindOrCreateIdentity(
            String objURI, String URL, ObjRef objectRef)
        {
            Identity idObj = null;

            BCLDebug.Assert(null != objURI, "null != objURI");

            bool bWellKnown = (URL != null);

            // Lookup the object in the identity table
            // for well-known objects we user the URL
            // as the hash-key (instead of just the objUri)
            idObj = ResolveIdentity(bWellKnown ? URL : objURI);
            if (bWellKnown &&
                (idObj != null) &&
                (idObj is ServerIdentity))
            {
                // We are trying to do a connect to a server wellknown object.
                throw new RemotingException(
                          String.Format(
                              CultureInfo.CurrentCulture, Environment.GetResourceString(
                                  "Remoting_WellKnown_CantDirectlyConnect"),
                              URL));
            }

            if (null == idObj)
            {
                // There is no entry for this uri in the IdTable.
                Message.DebugOut("RemotingService::FindOrCreateIdentity: Creating Identity\n");

                // This identity is being encountered for the first time.
                // We have to do the following things
                // (1) Create an identity object for the proxy
                // (2) Add the identity to the identity table
                // (3) Create a proxy for the object represented by the objref

                // Create a new identity
                //                        Identity should get only one string that is used for everything
                idObj = new Identity(objURI, URL);

                // We need to guarantee that finally is not interrupted so that the lock is released.
                // TableLock has a long path without reliability contract.  To avoid adding contract on
                // the path, we will use ReaderWriterLock directly.
                ReaderWriterLock rwlock         = TableLock;
                bool             takeAndRelease = !rwlock.IsWriterLockHeld;

                RuntimeHelpers.PrepareConstrainedRegions();
                try
                {
                    // Add it to the identity table
                    if (takeAndRelease)
                    {
                        rwlock.AcquireWriterLock(INFINITE);
                    }

                    // SetIdentity will give the correct Id if we raced
                    // between the ResolveIdentity call above and now.
                    //   (we are unmarshaling, and the server should guarantee
                    //    that the uri is unique, so we will use an existing identity
                    //    in case of a race)
                    idObj = SetIdentity(idObj, null, DuplicateIdentityOption.UseExisting);

                    idObj.RaceSetObjRef(objectRef);
                }
                finally
                {
                    if (takeAndRelease && rwlock.IsWriterLockHeld)
                    {
                        rwlock.ReleaseWriterLock();
                    }
                }
            }
            else
            {
                Message.DebugOut("RemotingService::FindOrCreateIdentity: Found Identity!\n");
            }
            BCLDebug.Assert(null != idObj, "null != idObj");
            return(idObj);
        }
Пример #35
0
 public static object Unmarshal(ObjRef objectRef, bool fRefine)
 {
     throw new NotImplementedException();
 }
Пример #36
0
 // Create a proxy for an object reference.
 public static Object Unmarshal(ObjRef objectRef)
 {
     return(Unmarshal(objectRef, false));
 }
Пример #37
0
 public static Object Unmarshal(ObjRef objectRef, bool fRefine)
 {
     // TODO
     return(null);
 }
Пример #38
0
        internal static bool IsWellFormed(ObjRef objectRef)
        {
            bool flag = true;

            return((((objectRef != null) && (objectRef.URI != null)) && ((objectRef.IsWellKnown() || objectRef.IsObjRefLite()) || ((objectRef.GetType() != orType) || (objectRef.ChannelInfo != null)))) && flag);
        }
Пример #39
0
        public static object Connect(Type classToProxy, string url, object data)
        {
            ObjRef objRef = new ObjRef(classToProxy, url, data);

            return(GetRemoteObject(objRef, classToProxy));
        }
Пример #40
0
 public SmuggledObjRef(System.Runtime.Remoting.ObjRef objRef)
 {
     this._objRef = objRef;
 }
Пример #41
0
 public static object Unmarshal(ObjRef objectRef)
 {
     return(Unmarshal(objectRef, true));
 }
Пример #42
0
        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);
        }
Пример #43
0
        [System.Security.SecurityCritical]  // auto-generated
        internal static Identity FindOrCreateIdentity(
            String objURI, String URL, ObjRef objectRef)
        {
            Identity idObj = null;

            Contract.Assert(null != objURI,"null != objURI");

            bool bWellKnown = (URL != null);

            // Lookup the object in the identity table
            // for well-known objects we user the URL
            // as the hash-key (instead of just the objUri)
            idObj = ResolveIdentity(bWellKnown ? URL : objURI);
            if (bWellKnown &&
                (idObj != null) &&
                (idObj is ServerIdentity))
            {
                // We are trying to do a connect to a server wellknown object.
                throw new RemotingException(
                    String.Format(
                        CultureInfo.CurrentCulture, Environment.GetResourceString(
                            "Remoting_WellKnown_CantDirectlyConnect"),
                        URL));                            
            }
                 
            if (null == idObj)
            {
                // There is no entry for this uri in the IdTable.
                Message.DebugOut("RemotingService::FindOrCreateIdentity: Creating Identity\n");

                // This identity is being encountered for the first time.
                // We have to do the following things
                // (1) Create an identity object for the proxy
                // (2) Add the identity to the identity table
                // (3) Create a proxy for the object represented by the objref      
                
                // Create a new identity
                // <EMAIL>GopalK:</EMAIL> Identity should get only one string that is used for everything
                idObj = new Identity(objURI, URL);                         

                // We need to guarantee that finally is not interrupted so that the lock is released.
                // TableLock has a long path without reliability contract.  To avoid adding contract on
                // the path, we will use ReaderWriterLock directly.
                ReaderWriterLock rwlock = TableLock;
                bool takeAndRelease = !rwlock.IsWriterLockHeld;

                RuntimeHelpers.PrepareConstrainedRegions();
                try
                {                
                    // Add it to the identity table
                    if (takeAndRelease)
                        rwlock.AcquireWriterLock(INFINITE);

                    // SetIdentity will give the correct Id if we ----d
                    // between the ResolveIdentity call above and now.
                    //   (we are unmarshaling, and the server should guarantee
                    //    that the uri is unique, so we will use an existing identity
                    //    in case of a ----)
                    idObj = SetIdentity(idObj, null, DuplicateIdentityOption.UseExisting);

                    idObj.RaceSetObjRef(objectRef);
                }
                finally
                {
                    if (takeAndRelease && rwlock.IsWriterLockHeld)
                    {
                        rwlock.ReleaseWriterLock();
                    }                
                }
            }
            else
            {
                Message.DebugOut("RemotingService::FindOrCreateIdentity: Found Identity!\n");
            }
            Contract.Assert(null != idObj,"null != idObj");
            return idObj;                
        }
Пример #44
0
        internal static ClientIdentity GetOrCreateClientIdentity(ObjRef objRef, Type proxyType, out object clientProxy)
        {
            // This method looks for an identity for the given url.
            // If an identity is not found, it creates the identity and
            // assigns it a proxy to the remote object.

            // Creates the client sink chain for the given url or channelData.
            // It will also get the object uri from the url.

            object channelData = objRef.ChannelInfo != null ? objRef.ChannelInfo.ChannelData : null;

            string       objectUri;
            IMessageSink sink = GetClientChannelSinkChain(objRef.URI, channelData, out objectUri);

            if (objectUri == null)
            {
                objectUri = objRef.URI;
            }

            lock (uri_hash)
            {
                clientProxy = null;
                string uri = GetNormalizedUri(objRef.URI);

                ClientIdentity identity = uri_hash [uri] as ClientIdentity;
                if (identity != null)
                {
                    // Object already registered
                    clientProxy = identity.ClientProxy;
                    if (clientProxy != null)
                    {
                        return(identity);
                    }

                    // The proxy has just been GCed, so its identity cannot
                    // be reused. Just dispose it.
                    DisposeIdentity(identity);
                }

                // Creates an identity and a proxy for the remote object

                identity             = new ClientIdentity(objectUri, objRef);
                identity.ChannelSink = sink;

                // Registers the identity
                uri_hash [uri] = identity;

                if (proxyType != null)
                {
                    RemotingProxy      proxy = new RemotingProxy(proxyType, identity);
                    CrossAppDomainSink cds   = sink as CrossAppDomainSink;
                    if (cds != null)
                    {
                        proxy.SetTargetDomain(cds.TargetDomainId);
                    }

                    clientProxy          = proxy.GetTransparentProxy();
                    identity.ClientProxy = (MarshalByRefObject)clientProxy;
                }

                return(identity);
            }
        }
        /// <summary>Stops the IPC server for the Integration Test service.</summary>
        private void StopServiceCallback(object sender, EventArgs e)
        {
            if (_stopServiceMenuCmd.Enabled)
            {
                _serviceChannel?.StopListening(null);

                _marshalledService = null;
                _serviceChannel = null;
                _service = null;

                SwapAvailableCommands(_stopServiceMenuCmd, _startServiceMenuCmd);
            }
        }
Пример #46
0
 internal void CacheObjRef(ObjRef objectRef)
 {
     _cachedObjRef = objectRef;
 }