Ejemplo n.º 1
0
        private void Export()
        {
            if (remoteObject != null)
            {
                throw new InvalidOperationException("object is already exported");
            }

            IProxyTypeBuilder builder = new SaoRemoteObjectProxyTypeBuilder(this);
            Type targetType           = this.objectFactory.GetType(targetName);

            if (targetType == null)
            {
                // perform full object retrieval if type cannot be predicted - this will
                // also cause any object creation exceptions to be thrown
                targetType = this.objectFactory.GetObject(targetName).GetType();
            }

            if (targetType.IsInterface)
            {
                builder.Interfaces = new Type[] { targetType };
                builder.TargetType = typeof(object);
            }
            else
            {
                if (interfaces != null && interfaces.Length > 0)
                {
                    builder.Interfaces = TypeResolutionUtils.ResolveInterfaceArray(interfaces);
                }
                builder.TargetType = targetType;
            }

            Type   proxyType = builder.BuildProxyType();
            string objectUri = (applicationName != null ? applicationName + "/" + serviceName : serviceName);

            ConstructorInfo proxyConstructor = proxyType.GetConstructor(Type.EmptyTypes);

            remoteObject = (MarshalByRefObject)proxyConstructor.Invoke(ObjectUtils.EmptyObjects);

            RemotingServices.Marshal(remoteObject, objectUri);

            #region Instrumentation

            if (LOG.IsDebugEnabled)
            {
                LOG.Debug(String.Format("Target '{0}' exported as '{1}'.", targetName, objectUri));
            }

            #endregion
        }
Ejemplo n.º 2
0
        private void Export()
        {
            if (remoteObject != null)
            {
                throw new InvalidOperationException("object is already exported");
            }

            IProxyTypeBuilder builder = new SaoRemoteObjectProxyTypeBuilder( this );
            Type targetType = this.objectFactory.GetType( targetName );
            if (targetType == null)
            {
                // perform full object retrieval if type cannot be predicted - this will 
                // also cause any object creation exceptions to be thrown
                targetType = this.objectFactory.GetObject(targetName).GetType();
            }

            if (targetType.IsInterface)
            {
                builder.Interfaces = new Type[] { targetType };
                builder.TargetType = typeof(object);
            }
            else
            {
                if (interfaces != null && interfaces.Length > 0)
                {
                    builder.Interfaces = TypeResolutionUtils.ResolveInterfaceArray(interfaces);
                }
                builder.TargetType = targetType;
            }

            Type proxyType = builder.BuildProxyType();
            string objectUri = (applicationName != null ? applicationName + "/" + serviceName : serviceName);

            ConstructorInfo proxyConstructor = proxyType.GetConstructor( Type.EmptyTypes );
            remoteObject = (MarshalByRefObject)proxyConstructor.Invoke( ObjectUtils.EmptyObjects );

            RemotingServices.Marshal( remoteObject, objectUri );

            #region Instrumentation

            if (LOG.IsDebugEnabled)
            {
                LOG.Debug( String.Format( "Target '{0}' exported as '{1}'.", targetName, objectUri ) );
            }

            #endregion
        }