Type BuildChannelListener(StuffPerListenUriInfo stuff,
                                  ServiceHostBase serviceHost,
                                  Uri listenUri,
                                  ListenUriMode listenUriMode,
                                  bool supportContextSession,
                                  out IChannelListener result)
        {
            Binding originalBinding = stuff.Endpoints[0].Binding;
            CustomBinding binding = new CustomBinding(originalBinding);
            BindingParameterCollection parameters = stuff.Parameters;

            Uri listenUriBaseAddress;
            string listenUriRelativeAddress;
            GetBaseAndRelativeAddresses(serviceHost, listenUri, binding.Scheme, out listenUriBaseAddress, out listenUriRelativeAddress);

            InternalDuplexBindingElement internalDuplex = null;
            InternalDuplexBindingElement.AddDuplexListenerSupport(binding, ref internalDuplex);

            // All types are supported to start
            bool reply = true;
            bool replySession = true;
            bool input = true;
            bool inputSession = true;
            bool duplex = true;
            bool duplexSession = true;
            string sessionContractName = null;
            string datagramContractName = null;
            // each endpoint adds constraints
            for (int i = 0; i < stuff.Endpoints.Count; ++i)
            {
                ContractDescription contract = stuff.Endpoints[i].Contract;
                if (contract.SessionMode == SessionMode.Required)
                {
                    sessionContractName = contract.Name;
                }
                if (contract.SessionMode == SessionMode.NotAllowed)
                {
                    datagramContractName = contract.Name;
                }

                System.Collections.IList endpointTypes = GetSupportedChannelTypes(contract);
                if (!endpointTypes.Contains(typeof(IReplyChannel)))
                {
                    reply = false;
                }
                if (!endpointTypes.Contains(typeof(IReplySessionChannel)))
                {
                    replySession = false;
                }
                if (!endpointTypes.Contains(typeof(IInputChannel)))
                {
                    input = false;
                }
                if (!endpointTypes.Contains(typeof(IInputSessionChannel)))
                {
                    inputSession = false;
                }
                if (!endpointTypes.Contains(typeof(IDuplexChannel)))
                {
                    duplex = false;
                }
                if (!endpointTypes.Contains(typeof(IDuplexSessionChannel)))
                {
                    duplexSession = false;
                }
            }

            if ((sessionContractName != null) && (datagramContractName != null))
            {
                string text = SR.GetString(SR.SFxCannotRequireBothSessionAndDatagram3, datagramContractName, sessionContractName, binding.Name);
                Exception error = new InvalidOperationException(text);
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(error);
            }

            List<Type> supportedChannelTypes = new List<Type>();
            if (input)
            {
                supportedChannelTypes.Add(typeof(IInputChannel));
            }
            if (inputSession)
            {
                supportedChannelTypes.Add(typeof(IInputSessionChannel));
            }
            if (reply)
            {
                supportedChannelTypes.Add(typeof(IReplyChannel));
            }
            if (replySession)
            {
                supportedChannelTypes.Add(typeof(IReplySessionChannel));
            }
            if (duplex)
            {
                supportedChannelTypes.Add(typeof(IDuplexChannel));
            }
            if (duplexSession)
            {
                supportedChannelTypes.Add(typeof(IDuplexSessionChannel));
            }
            // now we know what channel types we can use to support the contracts at this ListenUri
            Type returnValue = DispatcherBuilder.MaybeCreateListener(true, supportedChannelTypes.ToArray(), binding, parameters,
                                                                     listenUriBaseAddress, listenUriRelativeAddress, listenUriMode, serviceHost.ServiceThrottle, out result,
                                                                     supportContextSession && sessionContractName != null);
            if (result == null)
            {
                // we put a lot of work into creating a good error message, as this is a common case
                Dictionary<Type, byte> setOfChannelTypesSupportedByBinding = new Dictionary<Type, byte>();
                if (binding.CanBuildChannelListener<IInputChannel>())
                {
                    setOfChannelTypesSupportedByBinding.Add(typeof(IInputChannel), 0);
                }
                if (binding.CanBuildChannelListener<IReplyChannel>())
                {
                    setOfChannelTypesSupportedByBinding.Add(typeof(IReplyChannel), 0);
                }
                if (binding.CanBuildChannelListener<IDuplexChannel>())
                {
                    setOfChannelTypesSupportedByBinding.Add(typeof(IDuplexChannel), 0);
                }
                if (binding.CanBuildChannelListener<IInputSessionChannel>())
                {
                    setOfChannelTypesSupportedByBinding.Add(typeof(IInputSessionChannel), 0);
                }
                if (binding.CanBuildChannelListener<IReplySessionChannel>())
                {
                    setOfChannelTypesSupportedByBinding.Add(typeof(IReplySessionChannel), 0);
                }
                if (binding.CanBuildChannelListener<IDuplexSessionChannel>())
                {
                    setOfChannelTypesSupportedByBinding.Add(typeof(IDuplexSessionChannel), 0);
                }

                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(ChannelRequirements.CantCreateListenerException(
                                                                              setOfChannelTypesSupportedByBinding.Keys, supportedChannelTypes, originalBinding.Name));
            }
            return returnValue;
        }
 private System.Type BuildChannelListener(StuffPerListenUriInfo stuff, ServiceHostBase serviceHost, Uri listenUri, ListenUriMode listenUriMode, bool supportContextSession, out IChannelListener result)
 {
     Uri uri;
     string str;
     Binding binding = stuff.Endpoints[0].Binding;
     CustomBinding binding2 = new CustomBinding(binding);
     BindingParameterCollection parameters = stuff.Parameters;
     this.GetBaseAndRelativeAddresses(serviceHost, listenUri, binding2.Scheme, out uri, out str);
     InternalDuplexBindingElement internalDuplexBindingElement = null;
     InternalDuplexBindingElement.AddDuplexListenerSupport(binding2, ref internalDuplexBindingElement);
     bool flag = true;
     bool flag2 = true;
     bool flag3 = true;
     bool flag4 = true;
     bool flag5 = true;
     bool flag6 = true;
     string name = null;
     string str3 = null;
     for (int i = 0; i < stuff.Endpoints.Count; i++)
     {
         ContractDescription contract = stuff.Endpoints[i].Contract;
         if (contract.SessionMode == SessionMode.Required)
         {
             name = contract.Name;
         }
         if (contract.SessionMode == SessionMode.NotAllowed)
         {
             str3 = contract.Name;
         }
         IList supportedChannelTypes = GetSupportedChannelTypes(contract);
         if (!supportedChannelTypes.Contains(typeof(IReplyChannel)))
         {
             flag = false;
         }
         if (!supportedChannelTypes.Contains(typeof(IReplySessionChannel)))
         {
             flag2 = false;
         }
         if (!supportedChannelTypes.Contains(typeof(IInputChannel)))
         {
             flag3 = false;
         }
         if (!supportedChannelTypes.Contains(typeof(IInputSessionChannel)))
         {
             flag4 = false;
         }
         if (!supportedChannelTypes.Contains(typeof(IDuplexChannel)))
         {
             flag5 = false;
         }
         if (!supportedChannelTypes.Contains(typeof(IDuplexSessionChannel)))
         {
             flag6 = false;
         }
     }
     if ((name != null) && (str3 != null))
     {
         Exception exception = new InvalidOperationException(System.ServiceModel.SR.GetString("SFxCannotRequireBothSessionAndDatagram3", new object[] { str3, name, binding2.Name }));
         throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(exception);
     }
     List<System.Type> requiredChannels = new List<System.Type>();
     if (flag3)
     {
         requiredChannels.Add(typeof(IInputChannel));
     }
     if (flag4)
     {
         requiredChannels.Add(typeof(IInputSessionChannel));
     }
     if (flag)
     {
         requiredChannels.Add(typeof(IReplyChannel));
     }
     if (flag2)
     {
         requiredChannels.Add(typeof(IReplySessionChannel));
     }
     if (flag5)
     {
         requiredChannels.Add(typeof(IDuplexChannel));
     }
     if (flag6)
     {
         requiredChannels.Add(typeof(IDuplexSessionChannel));
     }
     System.Type type = MaybeCreateListener(true, requiredChannels.ToArray(), binding2, parameters, uri, str, listenUriMode, serviceHost.ServiceThrottle, out result, supportContextSession && (name != null));
     if (result != null)
     {
         return type;
     }
     Dictionary<System.Type, byte> dictionary = new Dictionary<System.Type, byte>();
     if (binding2.CanBuildChannelListener<IInputChannel>(new object[0]))
     {
         dictionary.Add(typeof(IInputChannel), 0);
     }
     if (binding2.CanBuildChannelListener<IReplyChannel>(new object[0]))
     {
         dictionary.Add(typeof(IReplyChannel), 0);
     }
     if (binding2.CanBuildChannelListener<IDuplexChannel>(new object[0]))
     {
         dictionary.Add(typeof(IDuplexChannel), 0);
     }
     if (binding2.CanBuildChannelListener<IInputSessionChannel>(new object[0]))
     {
         dictionary.Add(typeof(IInputSessionChannel), 0);
     }
     if (binding2.CanBuildChannelListener<IReplySessionChannel>(new object[0]))
     {
         dictionary.Add(typeof(IReplySessionChannel), 0);
     }
     if (binding2.CanBuildChannelListener<IDuplexSessionChannel>(new object[0]))
     {
         dictionary.Add(typeof(IDuplexSessionChannel), 0);
     }
     throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(ChannelRequirements.CantCreateListenerException(dictionary.Keys, requiredChannels, binding.Name));
 }
Example #3
0
        private static List <Type> GetSupportedChannelTypes(StuffPerListenUriInfo stuff)
        {
            Binding       originalBinding = stuff.Endpoints[0].Binding;
            CustomBinding binding         = new CustomBinding(originalBinding);

            // All types are supported to start
            bool   reply                = true;
            bool   replySession         = true;
            bool   input                = true;
            bool   inputSession         = true;
            bool   duplex               = true;
            bool   duplexSession        = true;
            string sessionContractName  = null;
            string datagramContractName = null;

            // each endpoint adds constraints
            for (int i = 0; i < stuff.Endpoints.Count; ++i)
            {
                ContractDescription contract = stuff.Endpoints[i].Contract;
                if (contract.SessionMode == SessionMode.Required)
                {
                    sessionContractName = contract.Name;
                }
                if (contract.SessionMode == SessionMode.NotAllowed)
                {
                    datagramContractName = contract.Name;
                }

                System.Collections.IList endpointTypes = GetSupportedChannelTypes(contract);
                if (!endpointTypes.Contains(typeof(IReplyChannel)))
                {
                    reply = false;
                }
                if (!endpointTypes.Contains(typeof(IReplySessionChannel)))
                {
                    replySession = false;
                }
                if (!endpointTypes.Contains(typeof(IInputChannel)))
                {
                    input = false;
                }
                if (!endpointTypes.Contains(typeof(IInputSessionChannel)))
                {
                    inputSession = false;
                }
                if (!endpointTypes.Contains(typeof(IDuplexChannel)))
                {
                    duplex = false;
                }
                if (!endpointTypes.Contains(typeof(IDuplexSessionChannel)))
                {
                    duplexSession = false;
                }
            }

            if ((sessionContractName != null) && (datagramContractName != null))
            {
                string    text  = SR.Format(SR.SFxCannotRequireBothSessionAndDatagram3, datagramContractName, sessionContractName, binding.Name);
                Exception error = new InvalidOperationException(text);
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(error);
            }

            // TODO: Restrict list further based on SessionMode constraints

            var supportedChannelTypes = new List <Type>();

            if (input)
            {
                supportedChannelTypes.Add(typeof(IInputChannel));
            }
            if (inputSession)
            {
                supportedChannelTypes.Add(typeof(IInputSessionChannel));
            }
            if (reply)
            {
                supportedChannelTypes.Add(typeof(IReplyChannel));
            }
            if (replySession)
            {
                supportedChannelTypes.Add(typeof(IReplySessionChannel));
            }
            if (duplex)
            {
                supportedChannelTypes.Add(typeof(IDuplexChannel));
            }
            if (duplexSession)
            {
                supportedChannelTypes.Add(typeof(IDuplexSessionChannel));
            }

            return(supportedChannelTypes);
        }
Example #4
0
        Type BuildChannelListener(StuffPerListenUriInfo stuff,
                                  ServiceHostBase serviceHost,
                                  Uri listenUri,
                                  ListenUriMode listenUriMode,
                                  out IChannelListener result)
        {
            Binding       originalBinding         = stuff.Endpoints[0].Binding;
            CustomBinding binding                 = new CustomBinding(originalBinding);
            BindingParameterCollection parameters = stuff.Parameters;

            Uri    listenUriBaseAddress;
            string listenUriRelativeAddress;

            GetBaseAndRelativeAddresses(serviceHost, listenUri, binding.Scheme, out listenUriBaseAddress, out listenUriRelativeAddress);

            // I don't believe InternalDuplexBindingElement is needed, at least not initially.
            // It looks like it's used when a channel factory is used to supply the outgoing channel
            // for duplex. I think it binds an incoming listener to an outgoing channel to acheive duplex.
            //InternalDuplexBindingElement internalDuplex = null;
            //InternalDuplexBindingElement.AddDuplexListenerSupport(binding, ref internalDuplex);

            // All types are supported to start
            bool   reply                = true;
            bool   replySession         = true;
            bool   input                = true;
            bool   inputSession         = true;
            bool   duplex               = true;
            bool   duplexSession        = true;
            string sessionContractName  = null;
            string datagramContractName = null;

            // each endpoint adds constraints
            for (int i = 0; i < stuff.Endpoints.Count; ++i)
            {
                ContractDescription contract = stuff.Endpoints[i].Contract;
                if (contract.SessionMode == SessionMode.Required)
                {
                    sessionContractName = contract.Name;
                }
                if (contract.SessionMode == SessionMode.NotAllowed)
                {
                    datagramContractName = contract.Name;
                }

                System.Collections.IList endpointTypes = GetSupportedChannelTypes(contract);
                if (!endpointTypes.Contains(typeof(IReplyChannel)))
                {
                    reply = false;
                }
                if (!endpointTypes.Contains(typeof(IReplySessionChannel)))
                {
                    replySession = false;
                }
                if (!endpointTypes.Contains(typeof(IInputChannel)))
                {
                    input = false;
                }
                if (!endpointTypes.Contains(typeof(IInputSessionChannel)))
                {
                    inputSession = false;
                }
                if (!endpointTypes.Contains(typeof(IDuplexChannel)))
                {
                    duplex = false;
                }
                if (!endpointTypes.Contains(typeof(IDuplexSessionChannel)))
                {
                    duplexSession = false;
                }
            }

            if ((sessionContractName != null) && (datagramContractName != null))
            {
                string    text  = SR.Format(SR.SFxCannotRequireBothSessionAndDatagram3, datagramContractName, sessionContractName, binding.Name);
                Exception error = new InvalidOperationException(text);
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(error);
            }

            List <Type> supportedChannelTypes = new List <Type>();

            if (input)
            {
                supportedChannelTypes.Add(typeof(IInputChannel));
            }
            if (inputSession)
            {
                supportedChannelTypes.Add(typeof(IInputSessionChannel));
            }
            if (reply)
            {
                supportedChannelTypes.Add(typeof(IReplyChannel));
            }
            if (replySession)
            {
                supportedChannelTypes.Add(typeof(IReplySessionChannel));
            }
            if (duplex)
            {
                supportedChannelTypes.Add(typeof(IDuplexChannel));
            }
            if (duplexSession)
            {
                supportedChannelTypes.Add(typeof(IDuplexSessionChannel));
            }
            // now we know what channel types we can use to support the contracts at this ListenUri
            Type returnValue = MaybeCreateListener(true, supportedChannelTypes.ToArray(), binding, parameters,
                                                   listenUriBaseAddress, listenUriRelativeAddress, listenUriMode, out result);

            if (result == null)
            {
                // we put a lot of work into creating a good error message, as this is a common case
                Dictionary <Type, byte> setOfChannelTypesSupportedByBinding = new Dictionary <Type, byte>();
                if (binding.CanBuildChannelListener <IInputChannel>())
                {
                    setOfChannelTypesSupportedByBinding.Add(typeof(IInputChannel), 0);
                }
                if (binding.CanBuildChannelListener <IReplyChannel>())
                {
                    setOfChannelTypesSupportedByBinding.Add(typeof(IReplyChannel), 0);
                }
                if (binding.CanBuildChannelListener <IDuplexChannel>())
                {
                    setOfChannelTypesSupportedByBinding.Add(typeof(IDuplexChannel), 0);
                }
                if (binding.CanBuildChannelListener <IInputSessionChannel>())
                {
                    setOfChannelTypesSupportedByBinding.Add(typeof(IInputSessionChannel), 0);
                }
                if (binding.CanBuildChannelListener <IReplySessionChannel>())
                {
                    setOfChannelTypesSupportedByBinding.Add(typeof(IReplySessionChannel), 0);
                }
                if (binding.CanBuildChannelListener <IDuplexSessionChannel>())
                {
                    setOfChannelTypesSupportedByBinding.Add(typeof(IDuplexSessionChannel), 0);
                }

                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(ChannelRequirements.CantCreateListenerException(
                                                                              setOfChannelTypesSupportedByBinding.Keys, supportedChannelTypes, originalBinding.Name));
            }
            return(returnValue);
        }