示例#1
0
 public override bool CanBuildChannelFactory <TChannel>(BindingContext context)
 {
     if (context == null)
     {
         throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("context");
     }
     InternalDuplexBindingElement.AddDuplexFactorySupport(context, ref this.internalDuplexBindingElement);
     if (typeof(TChannel) == typeof(IOutputSessionChannel))
     {
         if ((!context.CanBuildInnerChannelFactory <IRequestSessionChannel>() && !context.CanBuildInnerChannelFactory <IRequestChannel>()) && !context.CanBuildInnerChannelFactory <IDuplexSessionChannel>())
         {
             return(context.CanBuildInnerChannelFactory <IDuplexChannel>());
         }
         return(true);
     }
     if (typeof(TChannel) == typeof(IDuplexSessionChannel))
     {
         if (!context.CanBuildInnerChannelFactory <IDuplexSessionChannel>())
         {
             return(context.CanBuildInnerChannelFactory <IDuplexChannel>());
         }
         return(true);
     }
     if (!(typeof(TChannel) == typeof(IRequestSessionChannel)))
     {
         return(false);
     }
     if (!context.CanBuildInnerChannelFactory <IRequestSessionChannel>())
     {
         return(context.CanBuildInnerChannelFactory <IRequestChannel>());
     }
     return(true);
 }
示例#2
0
 public override bool CanBuildChannelListener <TChannel>(BindingContext context) where TChannel : class, IChannel
 {
     if (context == null)
     {
         throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("context");
     }
     InternalDuplexBindingElement.AddDuplexListenerSupport(context, ref this.internalDuplexBindingElement);
     if (typeof(TChannel) == typeof(IInputSessionChannel))
     {
         if ((!context.CanBuildInnerChannelListener <IReplySessionChannel>() && !context.CanBuildInnerChannelListener <IReplyChannel>()) && !context.CanBuildInnerChannelListener <IDuplexSessionChannel>())
         {
             return(context.CanBuildInnerChannelListener <IDuplexChannel>());
         }
         return(true);
     }
     if (typeof(TChannel) == typeof(IDuplexSessionChannel))
     {
         if (!context.CanBuildInnerChannelListener <IDuplexSessionChannel>())
         {
             return(context.CanBuildInnerChannelListener <IDuplexChannel>());
         }
         return(true);
     }
     if (!(typeof(TChannel) == typeof(IReplySessionChannel)))
     {
         return(false);
     }
     if (!context.CanBuildInnerChannelListener <IReplySessionChannel>())
     {
         return(context.CanBuildInnerChannelListener <IReplyChannel>());
     }
     return(true);
 }
示例#3
0
        public override T GetProperty <T>()
        {
            if (typeof(T) == typeof(IChannelListener))
            {
                return((T)(object)innerChannelListener);
            }

            if (typeof(T) == typeof(ISecurityCapabilities) && !this.providesCorrelation)
            {
                return(InternalDuplexBindingElement.GetSecurityCapabilities <T>(base.GetProperty <ISecurityCapabilities>()));
            }

            T baseProperty = base.GetProperty <T>();

            if (baseProperty != null)
            {
                return(baseProperty);
            }

            IChannelListener channelListener = innerChannelListener;

            if (channelListener != null)
            {
                return(channelListener.GetProperty <T>());
            }
            else
            {
                return(default(T));
            }
        }
示例#4
0
        internal InternalDuplexChannelFactory(InternalDuplexBindingElement bindingElement, BindingContext context, InputChannelDemuxer channelDemuxer, IChannelFactory <IOutputChannel> innerChannelFactory, LocalAddressProvider localAddressProvider) : base(context.Binding, innerChannelFactory)
        {
            this.channelDemuxer      = channelDemuxer;
            this.innerChannelFactory = innerChannelFactory;
            ChannelDemuxerFilter filter = new ChannelDemuxerFilter(new MatchNoneMessageFilter(), -2147483648);

            this.innerChannelListener = this.channelDemuxer.BuildChannelListener <IInputChannel>(filter);
            this.localAddressProvider = localAddressProvider;
            this.providesCorrelation  = bindingElement.ProvidesCorrelation;
        }
示例#5
0
 public override T GetProperty <T>(BindingContext context)
 {
     if (typeof(T) == typeof(ISecurityCapabilities) && !this.ProvidesCorrelation)
     {
         return(InternalDuplexBindingElement.GetSecurityCapabilities <T>(context.GetInnerProperty <ISecurityCapabilities>()));
     }
     else
     {
         return(context.GetInnerProperty <T>());
     }
 }
示例#6
0
 public static void AddDuplexListenerSupport(BindingContext context, ref InternalDuplexBindingElement internalDuplexBindingElement)
 {
     if ((((((!context.CanBuildInnerChannelListener <IDuplexChannel>() && (context.RemainingBindingElements.Find <CompositeDuplexBindingElement>() != null)) && (context.CanBuildInnerChannelFactory <IOutputChannel>() && context.CanBuildInnerChannelListener <IInputChannel>())) && !context.CanBuildInnerChannelListener <IReplyChannel>()) && !context.CanBuildInnerChannelListener <IReplySessionChannel>()) && !context.CanBuildInnerChannelListener <IInputSessionChannel>()) && !context.CanBuildInnerChannelListener <IDuplexSessionChannel>())
     {
         if (internalDuplexBindingElement == null)
         {
             internalDuplexBindingElement = new InternalDuplexBindingElement();
         }
         context.RemainingBindingElements.Insert(0, internalDuplexBindingElement);
     }
 }
示例#7
0
 public static void AddDuplexListenerSupport(CustomBinding binding, ref InternalDuplexBindingElement internalDuplexBindingElement)
 {
     if ((((((!binding.CanBuildChannelListener <IDuplexChannel>(new object[0]) && (binding.Elements.Find <CompositeDuplexBindingElement>() != null)) && (binding.CanBuildChannelFactory <IOutputChannel>(new object[0]) && binding.CanBuildChannelListener <IInputChannel>(new object[0]))) && !binding.CanBuildChannelListener <IReplyChannel>(new object[0])) && !binding.CanBuildChannelListener <IReplySessionChannel>(new object[0])) && !binding.CanBuildChannelListener <IInputSessionChannel>(new object[0])) && !binding.CanBuildChannelListener <IDuplexSessionChannel>(new object[0]))
     {
         if (internalDuplexBindingElement == null)
         {
             internalDuplexBindingElement = new InternalDuplexBindingElement();
         }
         binding.Elements.Insert(0, internalDuplexBindingElement);
     }
 }
示例#8
0
 public override IChannelFactory <TChannel> BuildChannelFactory <TChannel>(BindingContext context)
 {
     if (context == null)
     {
         throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("context");
     }
     this.VerifyTransportMode(context);
     this.SetSecuritySettings(context);
     InternalDuplexBindingElement.AddDuplexFactorySupport(context, ref this.internalDuplexBindingElement);
     if (typeof(TChannel) == typeof(IOutputSessionChannel))
     {
         if (context.CanBuildInnerChannelFactory <IRequestSessionChannel>())
         {
             return((IChannelFactory <TChannel>) new ReliableChannelFactory <TChannel, IRequestSessionChannel>(this, context.BuildInnerChannelFactory <IRequestSessionChannel>(), context.Binding));
         }
         if (context.CanBuildInnerChannelFactory <IRequestChannel>())
         {
             return((IChannelFactory <TChannel>) new ReliableChannelFactory <TChannel, IRequestChannel>(this, context.BuildInnerChannelFactory <IRequestChannel>(), context.Binding));
         }
         if (context.CanBuildInnerChannelFactory <IDuplexSessionChannel>())
         {
             return((IChannelFactory <TChannel>) new ReliableChannelFactory <TChannel, IDuplexSessionChannel>(this, context.BuildInnerChannelFactory <IDuplexSessionChannel>(), context.Binding));
         }
         if (context.CanBuildInnerChannelFactory <IDuplexChannel>())
         {
             return((IChannelFactory <TChannel>) new ReliableChannelFactory <TChannel, IDuplexChannel>(this, context.BuildInnerChannelFactory <IDuplexChannel>(), context.Binding));
         }
     }
     else if (typeof(TChannel) == typeof(IDuplexSessionChannel))
     {
         if (context.CanBuildInnerChannelFactory <IDuplexSessionChannel>())
         {
             return((IChannelFactory <TChannel>) new ReliableChannelFactory <TChannel, IDuplexSessionChannel>(this, context.BuildInnerChannelFactory <IDuplexSessionChannel>(), context.Binding));
         }
         if (context.CanBuildInnerChannelFactory <IDuplexChannel>())
         {
             return((IChannelFactory <TChannel>) new ReliableChannelFactory <TChannel, IDuplexChannel>(this, context.BuildInnerChannelFactory <IDuplexChannel>(), context.Binding));
         }
     }
     else if (typeof(TChannel) == typeof(IRequestSessionChannel))
     {
         if (context.CanBuildInnerChannelFactory <IRequestSessionChannel>())
         {
             return((IChannelFactory <TChannel>) new ReliableChannelFactory <TChannel, IRequestSessionChannel>(this, context.BuildInnerChannelFactory <IRequestSessionChannel>(), context.Binding));
         }
         if (context.CanBuildInnerChannelFactory <IRequestChannel>())
         {
             return((IChannelFactory <TChannel>) new ReliableChannelFactory <TChannel, IRequestChannel>(this, context.BuildInnerChannelFactory <IRequestChannel>(), context.Binding));
         }
     }
     throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgument("TChannel", System.ServiceModel.SR.GetString("ChannelTypeNotSupported", new object[] { typeof(TChannel) }));
 }
        internal ReliableSessionBindingElement(ReliableSessionBindingElement elementToBeCloned)
            : base(elementToBeCloned)
        {
            this.AcknowledgementInterval = elementToBeCloned.AcknowledgementInterval;
            this.FlowControlEnabled      = elementToBeCloned.FlowControlEnabled;
            this.InactivityTimeout       = elementToBeCloned.InactivityTimeout;
            this.MaxPendingChannels      = elementToBeCloned.MaxPendingChannels;
            this.MaxRetryCount           = elementToBeCloned.MaxRetryCount;
            this.MaxTransferWindowSize   = elementToBeCloned.MaxTransferWindowSize;
            this.Ordered = elementToBeCloned.Ordered;
            this.ReliableMessagingVersion = elementToBeCloned.ReliableMessagingVersion;

            this.internalDuplexBindingElement = elementToBeCloned.internalDuplexBindingElement;
        }
        public override T GetProperty <T>() where T : class
        {
            if (typeof(T) == typeof(IChannelFactory))
            {
                return((T)this.innerChannelFactory);
            }
            if ((typeof(T) == typeof(ISecurityCapabilities)) && !this.providesCorrelation)
            {
                return(InternalDuplexBindingElement.GetSecurityCapabilities <T>(base.GetProperty <ISecurityCapabilities>()));
            }
            T property = base.GetProperty <T>();

            if (property != null)
            {
                return(property);
            }
            return(this.innerChannelFactory.GetProperty <T>());
        }
示例#11
0
 internal ReliableSessionBindingElement(ReliableSessionBindingElement elementToBeCloned) : base(elementToBeCloned)
 {
     this.acknowledgementInterval = ReliableSessionDefaults.AcknowledgementInterval;
     this.flowControlEnabled      = true;
     this.inactivityTimeout       = ReliableSessionDefaults.InactivityTimeout;
     this.maxPendingChannels      = 4;
     this.maxRetryCount           = 8;
     this.maxTransferWindowSize   = 8;
     this.ordered = true;
     this.reliableMessagingVersion = System.ServiceModel.ReliableMessagingVersion.Default;
     this.AcknowledgementInterval  = elementToBeCloned.AcknowledgementInterval;
     this.FlowControlEnabled       = elementToBeCloned.FlowControlEnabled;
     this.InactivityTimeout        = elementToBeCloned.InactivityTimeout;
     this.MaxPendingChannels       = elementToBeCloned.MaxPendingChannels;
     this.MaxRetryCount            = elementToBeCloned.MaxRetryCount;
     this.MaxTransferWindowSize    = elementToBeCloned.MaxTransferWindowSize;
     this.Ordered = elementToBeCloned.Ordered;
     this.ReliableMessagingVersion     = elementToBeCloned.ReliableMessagingVersion;
     this.internalDuplexBindingElement = elementToBeCloned.internalDuplexBindingElement;
 }
示例#12
0
 private InternalDuplexBindingElement(InternalDuplexBindingElement elementToBeCloned) : base(elementToBeCloned)
 {
     this.clientChannelDemuxer = elementToBeCloned.ClientChannelDemuxer;
     this.providesCorrelation  = elementToBeCloned.ProvidesCorrelation;
 }
        public override IChannelListener <TChannel> BuildChannelListener <TChannel>(BindingContext context)
        {
            if (context == null)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("context");
            }

            this.VerifyTransportMode(context);
            this.SetSecuritySettings(context);

#pragma warning suppress 56506 // BindingContext guarantees BindingParameters is never null.
            IMessageFilterTable <EndpointAddress> table = context.BindingParameters.Find <IMessageFilterTable <EndpointAddress> >();

            InternalDuplexBindingElement.AddDuplexListenerSupport(context, ref this.internalDuplexBindingElement);

            if (typeof(TChannel) == typeof(IInputSessionChannel))
            {
                ReliableChannelListenerBase <IInputSessionChannel> listener = null;

                if (context.CanBuildInnerChannelListener <IReplySessionChannel>())
                {
                    listener = new ReliableInputListenerOverReplySession(this, context);
                }
                else if (context.CanBuildInnerChannelListener <IReplyChannel>())
                {
                    listener = new ReliableInputListenerOverReply(this, context);
                }
                else if (context.CanBuildInnerChannelListener <IDuplexSessionChannel>())
                {
                    listener = new ReliableInputListenerOverDuplexSession(this, context);
                }
                else if (context.CanBuildInnerChannelListener <IDuplexChannel>())
                {
                    listener = new ReliableInputListenerOverDuplex(this, context);
                }

                if (listener != null)
                {
                    listener.LocalAddresses = table;
                    return((IChannelListener <TChannel>)(object) listener);
                }
            }
            else if (typeof(TChannel) == typeof(IDuplexSessionChannel))
            {
                ReliableChannelListenerBase <IDuplexSessionChannel> listener = null;

                if (context.CanBuildInnerChannelListener <IDuplexSessionChannel>())
                {
                    listener = new ReliableDuplexListenerOverDuplexSession(this, context);
                }
                else if (context.CanBuildInnerChannelListener <IDuplexChannel>())
                {
                    listener = new ReliableDuplexListenerOverDuplex(this, context);
                }

                if (listener != null)
                {
                    listener.LocalAddresses = table;
                    return((IChannelListener <TChannel>)(object) listener);
                }
            }
            else if (typeof(TChannel) == typeof(IReplySessionChannel))
            {
                ReliableChannelListenerBase <IReplySessionChannel> listener = null;

                if (context.CanBuildInnerChannelListener <IReplySessionChannel>())
                {
                    listener = new ReliableReplyListenerOverReplySession(this, context);
                }
                else if (context.CanBuildInnerChannelListener <IReplyChannel>())
                {
                    listener = new ReliableReplyListenerOverReply(this, context);
                }

                if (listener != null)
                {
                    listener.LocalAddresses = table;
                    return((IChannelListener <TChannel>)(object) listener);
                }
            }

            throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgument("TChannel", SR.GetString(SR.ChannelTypeNotSupported, typeof(TChannel)));
        }
示例#14
0
        public override IChannelListener <TChannel> BuildChannelListener <TChannel>(BindingContext context) where TChannel : class, IChannel
        {
            if (context == null)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("context");
            }
            this.VerifyTransportMode(context);
            this.SetSecuritySettings(context);
            IMessageFilterTable <EndpointAddress> table = context.BindingParameters.Find <IMessageFilterTable <EndpointAddress> >();

            InternalDuplexBindingElement.AddDuplexListenerSupport(context, ref this.internalDuplexBindingElement);
            if (typeof(TChannel) == typeof(IInputSessionChannel))
            {
                ReliableChannelListenerBase <IInputSessionChannel> base2 = null;
                if (context.CanBuildInnerChannelListener <IReplySessionChannel>())
                {
                    base2 = new ReliableInputListenerOverReplySession(this, context);
                }
                else if (context.CanBuildInnerChannelListener <IReplyChannel>())
                {
                    base2 = new ReliableInputListenerOverReply(this, context);
                }
                else if (context.CanBuildInnerChannelListener <IDuplexSessionChannel>())
                {
                    base2 = new ReliableInputListenerOverDuplexSession(this, context);
                }
                else if (context.CanBuildInnerChannelListener <IDuplexChannel>())
                {
                    base2 = new ReliableInputListenerOverDuplex(this, context);
                }
                if (base2 != null)
                {
                    base2.LocalAddresses = table;
                    return((IChannelListener <TChannel>)base2);
                }
            }
            else if (typeof(TChannel) == typeof(IDuplexSessionChannel))
            {
                ReliableChannelListenerBase <IDuplexSessionChannel> base3 = null;
                if (context.CanBuildInnerChannelListener <IDuplexSessionChannel>())
                {
                    base3 = new ReliableDuplexListenerOverDuplexSession(this, context);
                }
                else if (context.CanBuildInnerChannelListener <IDuplexChannel>())
                {
                    base3 = new ReliableDuplexListenerOverDuplex(this, context);
                }
                if (base3 != null)
                {
                    base3.LocalAddresses = table;
                    return((IChannelListener <TChannel>)base3);
                }
            }
            else if (typeof(TChannel) == typeof(IReplySessionChannel))
            {
                ReliableChannelListenerBase <IReplySessionChannel> base4 = null;
                if (context.CanBuildInnerChannelListener <IReplySessionChannel>())
                {
                    base4 = new ReliableReplyListenerOverReplySession(this, context);
                }
                else if (context.CanBuildInnerChannelListener <IReplyChannel>())
                {
                    base4 = new ReliableReplyListenerOverReply(this, context);
                }
                if (base4 != null)
                {
                    base4.LocalAddresses = table;
                    return((IChannelListener <TChannel>)base4);
                }
            }
            throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgument("TChannel", System.ServiceModel.SR.GetString("ChannelTypeNotSupported", new object[] { typeof(TChannel) }));
        }
        public static ServiceChannelFactory BuildChannelFactory(ServiceEndpoint serviceEndpoint, bool useActiveAutoClose)
        {
            if (serviceEndpoint == null)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("serviceEndpoint");
            }

            serviceEndpoint.EnsureInvariants();
            serviceEndpoint.ValidateForClient();

            ChannelRequirements requirements;
            ContractDescription contractDescription = serviceEndpoint.Contract;

            ChannelRequirements.ComputeContractRequirements(contractDescription, out requirements);

            BindingParameterCollection parameters;
            ClientRuntime clientRuntime = DispatcherBuilder.BuildProxyBehavior(serviceEndpoint, out parameters);

            Binding binding = serviceEndpoint.Binding;

            Type[] requiredChannels = ChannelRequirements.ComputeRequiredChannels(ref requirements);

            CustomBinding  customBinding = new CustomBinding(binding);
            BindingContext context       = new BindingContext(customBinding, parameters);

            InternalDuplexBindingElement internalDuplexBindingElement = null;

            InternalDuplexBindingElement.AddDuplexFactorySupport(context, ref internalDuplexBindingElement);

            customBinding = new CustomBinding(context.RemainingBindingElements);
            customBinding.CopyTimeouts(serviceEndpoint.Binding);

            foreach (Type type in requiredChannels)
            {
                if (type == typeof(IOutputChannel) && customBinding.CanBuildChannelFactory <IOutputChannel>(parameters))
                {
                    return(new ServiceChannelFactoryOverOutput(customBinding.BuildChannelFactory <IOutputChannel>(parameters), clientRuntime, binding));
                }

                if (type == typeof(IRequestChannel) && customBinding.CanBuildChannelFactory <IRequestChannel>(parameters))
                {
                    return(new ServiceChannelFactoryOverRequest(customBinding.BuildChannelFactory <IRequestChannel>(parameters), clientRuntime, binding));
                }

                if (type == typeof(IDuplexChannel) && customBinding.CanBuildChannelFactory <IDuplexChannel>(parameters))
                {
                    if (requirements.usesReply &&
                        binding.CreateBindingElements().Find <TransportBindingElement>().ManualAddressing)
                    {
                        throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(
                                                                                      SR.GetString(SR.CantCreateChannelWithManualAddressing)));
                    }

                    return(new ServiceChannelFactoryOverDuplex(customBinding.BuildChannelFactory <IDuplexChannel>(parameters), clientRuntime, binding));
                }

                if (type == typeof(IOutputSessionChannel) && customBinding.CanBuildChannelFactory <IOutputSessionChannel>(parameters))
                {
                    return(new ServiceChannelFactoryOverOutputSession(customBinding.BuildChannelFactory <IOutputSessionChannel>(parameters), clientRuntime, binding, false));
                }

                if (type == typeof(IRequestSessionChannel) && customBinding.CanBuildChannelFactory <IRequestSessionChannel>(parameters))
                {
                    return(new ServiceChannelFactoryOverRequestSession(customBinding.BuildChannelFactory <IRequestSessionChannel>(parameters), clientRuntime, binding, false));
                }

                if (type == typeof(IDuplexSessionChannel) && customBinding.CanBuildChannelFactory <IDuplexSessionChannel>(parameters))
                {
                    if (requirements.usesReply &&
                        binding.CreateBindingElements().Find <TransportBindingElement>().ManualAddressing)
                    {
                        throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(
                                                                                      SR.GetString(SR.CantCreateChannelWithManualAddressing)));
                    }

                    return(new ServiceChannelFactoryOverDuplexSession(customBinding.BuildChannelFactory <IDuplexSessionChannel>(parameters), clientRuntime, binding, useActiveAutoClose));
                }
            }

            foreach (Type type in requiredChannels)
            {
                // For SessionMode.Allowed or SessionMode.NotAllowed we will accept session-ful variants as well
                if (type == typeof(IOutputChannel) && customBinding.CanBuildChannelFactory <IOutputSessionChannel>(parameters))
                {
                    return(new ServiceChannelFactoryOverOutputSession(customBinding.BuildChannelFactory <IOutputSessionChannel>(parameters), clientRuntime, binding, true));
                }

                if (type == typeof(IRequestChannel) && customBinding.CanBuildChannelFactory <IRequestSessionChannel>(parameters))
                {
                    return(new ServiceChannelFactoryOverRequestSession(customBinding.BuildChannelFactory <IRequestSessionChannel>(parameters), clientRuntime, binding, true));
                }

                // and for SessionMode.Required, it is possible that the InstanceContextProvider is handling the session management, so
                // accept datagram variants if that is the case
                if (type == typeof(IRequestSessionChannel) && customBinding.CanBuildChannelFactory <IRequestChannel>(parameters) &&
                    customBinding.GetProperty <IContextSessionProvider>(parameters) != null)
                {
                    return(new ServiceChannelFactoryOverRequest(customBinding.BuildChannelFactory <IRequestChannel>(parameters), clientRuntime, binding));
                }
            }

            // we put a lot of work into creating a good error message, as this is a common case
            Dictionary <Type, byte> supportedChannels = new Dictionary <Type, byte>();

            if (customBinding.CanBuildChannelFactory <IOutputChannel>(parameters))
            {
                supportedChannels.Add(typeof(IOutputChannel), 0);
            }
            if (customBinding.CanBuildChannelFactory <IRequestChannel>(parameters))
            {
                supportedChannels.Add(typeof(IRequestChannel), 0);
            }
            if (customBinding.CanBuildChannelFactory <IDuplexChannel>(parameters))
            {
                supportedChannels.Add(typeof(IDuplexChannel), 0);
            }
            if (customBinding.CanBuildChannelFactory <IOutputSessionChannel>(parameters))
            {
                supportedChannels.Add(typeof(IOutputSessionChannel), 0);
            }
            if (customBinding.CanBuildChannelFactory <IRequestSessionChannel>(parameters))
            {
                supportedChannels.Add(typeof(IRequestSessionChannel), 0);
            }
            if (customBinding.CanBuildChannelFactory <IDuplexSessionChannel>(parameters))
            {
                supportedChannels.Add(typeof(IDuplexSessionChannel), 0);
            }

            throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(ChannelRequirements.CantCreateChannelException(
                                                                          supportedChannels.Keys, requiredChannels, binding.Name));
        }
示例#16
0
        public static ServiceChannelFactory BuildChannelFactory(ServiceEndpoint serviceEndpoint, bool useActiveAutoClose)
        {
            ChannelRequirements        requirements;
            BindingParameterCollection parameters;

            if (serviceEndpoint == null)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("serviceEndpoint");
            }
            serviceEndpoint.EnsureInvariants();
            serviceEndpoint.ValidateForClient();
            ChannelRequirements.ComputeContractRequirements(serviceEndpoint.Contract, out requirements);
            System.ServiceModel.Dispatcher.ClientRuntime clientRuntime = DispatcherBuilder.BuildProxyBehavior(serviceEndpoint, out parameters);
            Binding binding = serviceEndpoint.Binding;

            System.Type[]  requiredChannels = ChannelRequirements.ComputeRequiredChannels(ref requirements);
            CustomBinding  binding2         = new CustomBinding(binding);
            BindingContext context          = new BindingContext(binding2, parameters);
            InternalDuplexBindingElement internalDuplexBindingElement = null;

            InternalDuplexBindingElement.AddDuplexFactorySupport(context, ref internalDuplexBindingElement);
            binding2 = new CustomBinding(context.RemainingBindingElements);
            binding2.CopyTimeouts(serviceEndpoint.Binding);
            foreach (System.Type type in requiredChannels)
            {
                if ((type == typeof(IOutputChannel)) && binding2.CanBuildChannelFactory <IOutputChannel>(parameters))
                {
                    return(new ServiceChannelFactoryOverOutput(binding2.BuildChannelFactory <IOutputChannel>(parameters), clientRuntime, binding));
                }
                if ((type == typeof(IRequestChannel)) && binding2.CanBuildChannelFactory <IRequestChannel>(parameters))
                {
                    return(new ServiceChannelFactoryOverRequest(binding2.BuildChannelFactory <IRequestChannel>(parameters), clientRuntime, binding));
                }
                if ((type == typeof(IDuplexChannel)) && binding2.CanBuildChannelFactory <IDuplexChannel>(parameters))
                {
                    if (requirements.usesReply && binding.CreateBindingElements().Find <TransportBindingElement>().ManualAddressing)
                    {
                        throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(System.ServiceModel.SR.GetString("CantCreateChannelWithManualAddressing")));
                    }
                    return(new ServiceChannelFactoryOverDuplex(binding2.BuildChannelFactory <IDuplexChannel>(parameters), clientRuntime, binding));
                }
                if ((type == typeof(IOutputSessionChannel)) && binding2.CanBuildChannelFactory <IOutputSessionChannel>(parameters))
                {
                    return(new ServiceChannelFactoryOverOutputSession(binding2.BuildChannelFactory <IOutputSessionChannel>(parameters), clientRuntime, binding, false));
                }
                if ((type == typeof(IRequestSessionChannel)) && binding2.CanBuildChannelFactory <IRequestSessionChannel>(parameters))
                {
                    return(new ServiceChannelFactoryOverRequestSession(binding2.BuildChannelFactory <IRequestSessionChannel>(parameters), clientRuntime, binding, false));
                }
                if ((type == typeof(IDuplexSessionChannel)) && binding2.CanBuildChannelFactory <IDuplexSessionChannel>(parameters))
                {
                    if (requirements.usesReply && binding.CreateBindingElements().Find <TransportBindingElement>().ManualAddressing)
                    {
                        throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(System.ServiceModel.SR.GetString("CantCreateChannelWithManualAddressing")));
                    }
                    return(new ServiceChannelFactoryOverDuplexSession(binding2.BuildChannelFactory <IDuplexSessionChannel>(parameters), clientRuntime, binding, useActiveAutoClose));
                }
            }
            foreach (System.Type type2 in requiredChannels)
            {
                if ((type2 == typeof(IOutputChannel)) && binding2.CanBuildChannelFactory <IOutputSessionChannel>(parameters))
                {
                    return(new ServiceChannelFactoryOverOutputSession(binding2.BuildChannelFactory <IOutputSessionChannel>(parameters), clientRuntime, binding, true));
                }
                if ((type2 == typeof(IRequestChannel)) && binding2.CanBuildChannelFactory <IRequestSessionChannel>(parameters))
                {
                    return(new ServiceChannelFactoryOverRequestSession(binding2.BuildChannelFactory <IRequestSessionChannel>(parameters), clientRuntime, binding, true));
                }
                if (((type2 == typeof(IRequestSessionChannel)) && binding2.CanBuildChannelFactory <IRequestChannel>(parameters)) && (binding2.GetProperty <IContextSessionProvider>(parameters) != null))
                {
                    return(new ServiceChannelFactoryOverRequest(binding2.BuildChannelFactory <IRequestChannel>(parameters), clientRuntime, binding));
                }
            }
            Dictionary <System.Type, byte> dictionary = new Dictionary <System.Type, byte>();

            if (binding2.CanBuildChannelFactory <IOutputChannel>(parameters))
            {
                dictionary.Add(typeof(IOutputChannel), 0);
            }
            if (binding2.CanBuildChannelFactory <IRequestChannel>(parameters))
            {
                dictionary.Add(typeof(IRequestChannel), 0);
            }
            if (binding2.CanBuildChannelFactory <IDuplexChannel>(parameters))
            {
                dictionary.Add(typeof(IDuplexChannel), 0);
            }
            if (binding2.CanBuildChannelFactory <IOutputSessionChannel>(parameters))
            {
                dictionary.Add(typeof(IOutputSessionChannel), 0);
            }
            if (binding2.CanBuildChannelFactory <IRequestSessionChannel>(parameters))
            {
                dictionary.Add(typeof(IRequestSessionChannel), 0);
            }
            if (binding2.CanBuildChannelFactory <IDuplexSessionChannel>(parameters))
            {
                dictionary.Add(typeof(IDuplexSessionChannel), 0);
            }
            throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(ChannelRequirements.CantCreateChannelException(dictionary.Keys, requiredChannels, binding.Name));
        }
示例#17
0
 internal InternalDuplexChannelListener(InternalDuplexBindingElement bindingElement, BindingContext context)
     : base(context.Binding, context.Clone().BuildInnerChannelListener <IInputChannel>())
 {
     this.innerChannelFactory = context.BuildInnerChannelFactory <IOutputChannel>();
     this.providesCorrelation = bindingElement.ProvidesCorrelation;
 }