CreateProxyType() public static method

public static CreateProxyType ( Type requestedType, ContractDescription cd, bool duplex ) : Type
requestedType System.Type
cd System.ServiceModel.Description.ContractDescription
duplex bool
return System.Type
        public virtual TChannel CreateChannel(InstanceContext callbackInstance, EndpointAddress address, Uri via)
        {
            if (callbackInstance == null)
            {
                throw new ArgumentNullException("callbackInstance");
            }

            EnsureOpened();
#if DISABLE_REAL_PROXY
            Type type = ClientProxyGenerator.CreateProxyType(typeof(TChannel), Endpoint.Contract, true);
            // in .NET and SL2, it seems that the proxy is RealProxy.
            // But since there is no remoting in SL2 (and we have
            // no special magic), we have to use different approach
            // that should work either.
            object proxy = Activator.CreateInstance(type, new object [] { Endpoint, this, address, via });
#elif !MOBILE && !XAMMAC_4_5
            object proxy = new ClientRealProxy(typeof(TChannel), new DuplexClientRuntimeChannel(Endpoint, this, address, via), true).GetTransparentProxy();
#else
            object proxy;
            throw new NotImplementedException();
#endif

            ((IDuplexContextChannel)proxy).CallbackInstance = callbackInstance;

            return((TChannel)proxy);
        }
        public virtual TChannel CreateChannel(EndpointAddress address, Uri via)
        {
#if MONOTOUCH
            throw new InvalidOperationException("MonoTouch does not support dynamic proxy code generation. Override this method or its caller to return specific client proxy instance");
#else
            var existing = Endpoint.Address;
            try
            {
                Endpoint.Address = address;
                EnsureOpened();
                Endpoint.Validate();
#if DISABLE_REAL_PROXY
                Type type = ClientProxyGenerator.CreateProxyType(typeof(TChannel), Endpoint.Contract, false);
                // in .NET and SL2, it seems that the proxy is RealProxy.
                // But since there is no remoting in SL2 (and we have
                // no special magic), we have to use different approach
                // that should work either.
                var proxy = (IClientChannel)Activator.CreateInstance(type, new object [] { Endpoint, this, address ?? Endpoint.Address, via });
#else
                var proxy = (IClientChannel) new ClientRealProxy(typeof(TChannel), new ClientRuntimeChannel(Endpoint, this, address ?? Endpoint.Address, via), false).GetTransparentProxy();
#endif
                proxy.Opened += delegate
                {
                    OpenedChannels.Add(proxy);
                };
                proxy.Closing += delegate
                {
                    OpenedChannels.Remove(proxy);
                };

                return((TChannel)proxy);
            }
            catch (TargetInvocationException ex)
            {
                if (ex.InnerException != null)
                {
                    throw ex.InnerException;
                }
                else
                {
                    throw;
                }
            }
            finally
            {
                Endpoint.Address = existing;
            }
#endif
        }
Ejemplo n.º 3
0
        public virtual TChannel CreateChannel(EndpointAddress address, Uri via)
        {
#if MONOTOUCH
            throw new InvalidOperationException("MonoTouch does not support dynamic proxy code generation. Override this method or its caller to return specific client proxy instance");
#else
            EnsureOpened();
            Endpoint.Validate();
            Type type = ClientProxyGenerator.CreateProxyType(typeof(TChannel), Endpoint.Contract, false);
            // in .NET and SL2, it seems that the proxy is RealProxy.
            // But since there is no remoting in SL2 (and we have
            // no special magic), we have to use different approach
            // that should work either.
            object proxy = Activator.CreateInstance(type, new object [] { Endpoint, this, address ?? Endpoint.Address, via });
            return((TChannel)proxy);
#endif
        }
Ejemplo n.º 4
0
        public virtual TChannel CreateChannel(InstanceContext callbackInstance, EndpointAddress address, Uri via)
        {
            if (callbackInstance == null)
            {
                throw new ArgumentNullException("callbackInstance");
            }

            EnsureOpened();
            Type type = ClientProxyGenerator.CreateProxyType(typeof(TChannel), Endpoint.Contract, true);
            // in .NET and SL2, it seems that the proxy is RealProxy.
            // But since there is no remoting in SL2 (and we have
            // no special magic), we have to use different approach
            // that should work either.
            object proxy = Activator.CreateInstance(type, new object [] { Endpoint, this, address, via });

            ((DuplexClientRuntimeChannel)proxy).CallbackInstance = callbackInstance;

            return((TChannel)proxy);
        }