Example #1
0
        BuildChannelListener <TChannel> (
            Uri listenUriBaseAddress,
            string listenUriRelativeAddress,
            ListenUriMode listenUriMode,
            BindingParameterCollection parameters)
            where TChannel : class, IChannel
        {
            if (listenUriBaseAddress == null)
            {
                throw new ArgumentNullException("listenUriBaseAddress");
            }
            if (listenUriRelativeAddress == null)
            {
                throw new ArgumentNullException("listenUriRelativeAddress");
            }
            if (parameters == null)
            {
                throw new ArgumentNullException("parameters");
            }
            BindingContext ctx = CreateContext(listenUriBaseAddress,
                                               listenUriRelativeAddress,
                                               listenUriMode,
                                               parameters);

            return(ctx.BuildInnerChannelListener <TChannel> ());
        }
 public static bool IsDefined(ListenUriMode mode)
 {
     if (mode != ListenUriMode.Explicit)
     {
         return(mode == ListenUriMode.Unique);
     }
     return(true);
 }
 public static bool IsDefined(ListenUriMode mode)
 {
     if (mode != ListenUriMode.Explicit)
     {
         return (mode == ListenUriMode.Unique);
     }
     return true;
 }
Example #4
0
 void Snippet6()
 {
     // <Snippet6>
     CustomBinding binding              = new CustomBinding();
     BindingParameterCollection bpCol   = new BindingParameterCollection();
     BindingContext             context = new BindingContext(binding, bpCol);
     ListenUriMode mode = context.ListenUriMode;
     // </Snippet6>
 }
Example #5
0
 BindingContext(CustomBinding binding,
                BindingElementCollection remainingBindingElements,
                BindingParameterCollection parameters,
                Uri listenUriBaseAddress,
                string listenUriRelativeAddress,
                ListenUriMode listenUriMode)
 {
     Initialize(binding, remainingBindingElements, parameters, listenUriBaseAddress, listenUriRelativeAddress, listenUriMode);
 }
Example #6
0
 public BindingContext(CustomBinding binding,
                       BindingParameterCollection parameters,
                       Uri listenUriBaseAddress,
                       string listenUriRelativeAddress,
                       ListenUriMode listenUriMode)
     : this(binding, parameters)
 {
     listen_uri_base     = listenUriBaseAddress;
     listen_uri_relative = listenUriRelativeAddress;
     listen_uri_mode     = listenUriMode;
 }
Example #7
0
        private void Initialize(CustomBinding binding,
                                BindingElementCollection remainingBindingElements,
                                BindingParameterCollection parameters,
                                Uri listenUriBaseAddress,
                                string listenUriRelativeAddress,
                                ListenUriMode listenUriMode)
        {
            _binding = binding;

            _remainingBindingElements = new BindingElementCollection(remainingBindingElements);
            _bindingParameters        = new BindingParameterCollection(parameters);
            _listenUriBaseAddress     = listenUriBaseAddress;
            _listenUriRelativeAddress = listenUriRelativeAddress;
            _listenUriMode            = listenUriMode;
        }
Example #8
0
 BindingContext CreateContext(
     Uri listenUriBaseAddress,
     string listenUriRelativeAddress,
     ListenUriMode listenUriMode,
     BindingParameterCollection parameters)
 {
     // FIXME: it seems that binding elements are
     // "validated" so that the last item is a transport.
     return(new BindingContext(
                new CustomBinding(this),
                parameters,
                listenUriBaseAddress,
                listenUriRelativeAddress,
                listenUriMode));
 }
Example #9
0
        void InitializeUri(Uri baseAddress, string relativeAddress, ListenUriMode mode)
        {
            switch (mode)
            {
            case ListenUriMode.Explicit:
                this.InitializeUri(baseAddress, relativeAddress);
                break;

            case ListenUriMode.Unique:
            {
                //This listener sets unique uris using the host name only.
                this.InitializeUniqueUri(baseAddress.Host);
                break;
            }
            }
        }
Example #10
0
        BuildChannelListener <TChannel> (
            Uri listenUriBaseAddress,
            string listenUriRelativeAddress,
            ListenUriMode listenUriMode,
            params object [] parameters)
            where TChannel : class, IChannel
        {
            BindingParameterCollection pl =
                new BindingParameterCollection();

            foreach (object o in parameters)
            {
                pl.Add(o);
            }
            return(BuildChannelListener <TChannel> (
                       listenUriBaseAddress,
                       listenUriRelativeAddress,
                       listenUriMode,
                       pl));
        }
Example #11
0
 // deep clone .ctor().
 BindingContext(CustomBinding binding,
                BindingParameterCollection parms,
                BindingElementCollection elems,
                Uri listenUriBaseAddress,
                string listenUriRelativeAddress,
                ListenUriMode listenUriMode)
 {
     this.binding = new CustomBinding(binding);
     parameters   = new BindingParameterCollection();
     foreach (var item in parms)
     {
         parameters.Add(item);
     }
     this.elements = new BindingElementCollection();
     foreach (var item in elems)
     {
         this.elements.Add(item);
     }
     listen_uri_base     = listenUriBaseAddress;
     listen_uri_relative = listenUriRelativeAddress;
     listen_uri_mode     = listenUriMode;
 }
Example #12
0
 public ListenUriInfo(Uri listenUri, ListenUriMode listenUriMode)
 {
     _listenUri     = listenUri;
     _listenUriMode = listenUriMode;
 }
Example #13
0
        public BindingContext(CustomBinding binding, BindingParameterCollection parameters, Uri listenUriBaseAddress, string listenUriRelativeAddress, ListenUriMode listenUriMode)
        {
            if (binding == null)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof(binding));
            }
            if (listenUriRelativeAddress == null)
            {
                listenUriRelativeAddress = string.Empty;
            }
            if (!ListenUriModeHelper.IsDefined(listenUriMode))
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException(nameof(listenUriMode)));
            }

            Initialize(binding, binding.Elements, parameters, listenUriBaseAddress, listenUriRelativeAddress, listenUriMode);
        }
Example #14
0
 public override IChannelListener <TChannel> BuildChannelListener <TChannel>(Uri listenUriBaseAddress,
                                                                             string listenUriRelativeAddress, ListenUriMode listenUriMode, BindingParameterCollection parameters)
 {
     throw new PlatformNotSupportedException("BuildChannelListener not supported for HTTP");
 }
 public virtual IChannelListener <TChannel> BuildChannelListener <TChannel>(Uri listenUriBaseAddress, string listenUriRelativeAddress, ListenUriMode listenUriMode, params object[] parameters)
     where TChannel : class, IChannel
 {
     return(this.BuildChannelListener <TChannel>(listenUriBaseAddress, listenUriRelativeAddress, listenUriMode, new BindingParameterCollection(parameters)));
 }
 static public bool IsDefined(ListenUriMode mode)
 {
     return mode == ListenUriMode.Explicit
         || mode == ListenUriMode.Unique;
 }
        public virtual IChannelListener <TChannel> BuildChannelListener <TChannel>(Uri listenUriBaseAddress, string listenUriRelativeAddress, ListenUriMode listenUriMode, BindingParameterCollection parameters)
            where TChannel : class, IChannel
        {
            EnsureInvariants();
            BindingContext context = new BindingContext(new CustomBinding(this), parameters, listenUriBaseAddress, listenUriRelativeAddress, listenUriMode);
            IChannelListener <TChannel> channelListener = context.BuildInnerChannelListener <TChannel>();

            context.ValidateBindingElementsConsumed();
            this.ValidateSecurityCapabilities(channelListener.GetProperty <ISecurityCapabilities>(), parameters);

            return(channelListener);
        }
Example #18
0
 static public bool IsDefined(ListenUriMode mode)
 {
     return(mode == ListenUriMode.Explicit ||
            mode == ListenUriMode.Unique);
 }
Example #19
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);
        }
        static Type MaybeCreateListener(bool actuallyCreate, Type[] supportedChannels,
                                                 Binding binding, BindingParameterCollection parameters,
                                                 Uri listenUriBaseAddress, string listenUriRelativeAddress,
                                                 ListenUriMode listenUriMode, ServiceThrottle throttle,
                                                 out IChannelListener result, bool supportContextSession)
        {
            // if actuallyCreate is true, then this behaves like CreateListener()
            // else this behaves like CanCreateListener()
            // result is channel type that was (would be) created, null if can't create
            // 
            // Ugly API helps refactor common code in these two similar-but-different methods

            result = null;

            for (int i = 0; i < supportedChannels.Length; i++)
            {
                Type channelType = supportedChannels[i];

                if (channelType == typeof(IInputChannel))
                {
                    if (binding.CanBuildChannelListener<IInputChannel>(parameters))
                    {
                        if (actuallyCreate)
                        {
                            result = binding.BuildChannelListener<IInputChannel>(listenUriBaseAddress, listenUriRelativeAddress, listenUriMode, parameters);
                        }
                        return typeof(IInputChannel);
                    }
                }
                if (channelType == typeof(IReplyChannel))
                {
                    if (binding.CanBuildChannelListener<IReplyChannel>(parameters))
                    {
                        if (actuallyCreate)
                        {
                            result = binding.BuildChannelListener<IReplyChannel>(listenUriBaseAddress, listenUriRelativeAddress, listenUriMode, parameters);
                        }
                        return typeof(IReplyChannel);
                    }
                }
                if (channelType == typeof(IDuplexChannel))
                {
                    if (binding.CanBuildChannelListener<IDuplexChannel>(parameters))
                    {
                        if (actuallyCreate)
                        {
                            result = binding.BuildChannelListener<IDuplexChannel>(listenUriBaseAddress, listenUriRelativeAddress, listenUriMode, parameters);
                        }
                        return typeof(IDuplexChannel);
                    }
                }
                if (channelType == typeof(IInputSessionChannel))
                {
                    if (binding.CanBuildChannelListener<IInputSessionChannel>(parameters))
                    {
                        if (actuallyCreate)
                        {
                            result = binding.BuildChannelListener<IInputSessionChannel>(listenUriBaseAddress, listenUriRelativeAddress, listenUriMode, parameters);
                        }
                        return typeof(IInputSessionChannel);
                    }
                }
                if (channelType == typeof(IReplySessionChannel))
                {
                    if (binding.CanBuildChannelListener<IReplySessionChannel>(parameters))
                    {
                        if (actuallyCreate)
                        {
                            result = binding.BuildChannelListener<IReplySessionChannel>(listenUriBaseAddress, listenUriRelativeAddress, listenUriMode, parameters);
                        }
                        return typeof(IReplySessionChannel);
                    }
                }
                if (channelType == typeof(IDuplexSessionChannel))
                {
                    if (binding.CanBuildChannelListener<IDuplexSessionChannel>(parameters))
                    {
                        if (actuallyCreate)
                        {
                            result = binding.BuildChannelListener<IDuplexSessionChannel>(listenUriBaseAddress, listenUriRelativeAddress, listenUriMode, parameters);
                        }
                        return typeof(IDuplexSessionChannel);
                    }
                }
            }

            // If the binding does not support the type natively, try to adapt
            for (int i = 0; i < supportedChannels.Length; i++)
            {
                Type channelType = supportedChannels[i];

                // For SessionMode.Allowed or SessionMode.NotAllowed we will accept session-ful variants as well and adapt them
                if (channelType == typeof(IInputChannel))
                {
                    if (binding.CanBuildChannelListener<IInputSessionChannel>(parameters))
                    {
                        if (actuallyCreate)
                        {
                            IChannelListener<IInputSessionChannel> temp = binding.BuildChannelListener<IInputSessionChannel>(listenUriBaseAddress, listenUriRelativeAddress, listenUriMode, parameters);
                            result = DatagramAdapter.GetInputListener(temp, throttle, binding);
                        }
                        return typeof(IInputSessionChannel);
                    }
                }

                if (channelType == typeof(IReplyChannel))
                {
                    if (binding.CanBuildChannelListener<IReplySessionChannel>(parameters))
                    {
                        if (actuallyCreate)
                        {
                            IChannelListener<IReplySessionChannel> temp = binding.BuildChannelListener<IReplySessionChannel>(listenUriBaseAddress, listenUriRelativeAddress, listenUriMode, parameters);
                            result = DatagramAdapter.GetReplyListener(temp, throttle, binding);
                        }
                        return typeof(IReplySessionChannel);
                    }
                }

                if (supportContextSession)
                {
                    // 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 (channelType == typeof(IReplySessionChannel))
                    {
                        if (binding.CanBuildChannelListener<IReplyChannel>(parameters)
                            && binding.GetProperty<IContextSessionProvider>(parameters) != null)
                        {
                            if (actuallyCreate)
                            {
                                result = binding.BuildChannelListener<IReplyChannel>(listenUriBaseAddress, listenUriRelativeAddress, listenUriMode, parameters);
                            }
                            return typeof(IReplyChannel);
                        }
                    }
                }
            }

            return null;
        }
        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));
 }
 private static System.Type MaybeCreateListener(bool actuallyCreate, System.Type[] supportedChannels, Binding binding, BindingParameterCollection parameters, Uri listenUriBaseAddress, string listenUriRelativeAddress, ListenUriMode listenUriMode, ServiceThrottle throttle, out IChannelListener result, bool supportContextSession)
 {
     result = null;
     for (int i = 0; i < supportedChannels.Length; i++)
     {
         System.Type type = supportedChannels[i];
         if ((type == typeof(IInputChannel)) && binding.CanBuildChannelListener<IInputChannel>(parameters))
         {
             if (actuallyCreate)
             {
                 result = binding.BuildChannelListener<IInputChannel>(listenUriBaseAddress, listenUriRelativeAddress, listenUriMode, parameters);
             }
             return typeof(IInputChannel);
         }
         if ((type == typeof(IReplyChannel)) && binding.CanBuildChannelListener<IReplyChannel>(parameters))
         {
             if (actuallyCreate)
             {
                 result = binding.BuildChannelListener<IReplyChannel>(listenUriBaseAddress, listenUriRelativeAddress, listenUriMode, parameters);
             }
             return typeof(IReplyChannel);
         }
         if ((type == typeof(IDuplexChannel)) && binding.CanBuildChannelListener<IDuplexChannel>(parameters))
         {
             if (actuallyCreate)
             {
                 result = binding.BuildChannelListener<IDuplexChannel>(listenUriBaseAddress, listenUriRelativeAddress, listenUriMode, parameters);
             }
             return typeof(IDuplexChannel);
         }
         if ((type == typeof(IInputSessionChannel)) && binding.CanBuildChannelListener<IInputSessionChannel>(parameters))
         {
             if (actuallyCreate)
             {
                 result = binding.BuildChannelListener<IInputSessionChannel>(listenUriBaseAddress, listenUriRelativeAddress, listenUriMode, parameters);
             }
             return typeof(IInputSessionChannel);
         }
         if ((type == typeof(IReplySessionChannel)) && binding.CanBuildChannelListener<IReplySessionChannel>(parameters))
         {
             if (actuallyCreate)
             {
                 result = binding.BuildChannelListener<IReplySessionChannel>(listenUriBaseAddress, listenUriRelativeAddress, listenUriMode, parameters);
             }
             return typeof(IReplySessionChannel);
         }
         if ((type == typeof(IDuplexSessionChannel)) && binding.CanBuildChannelListener<IDuplexSessionChannel>(parameters))
         {
             if (actuallyCreate)
             {
                 result = binding.BuildChannelListener<IDuplexSessionChannel>(listenUriBaseAddress, listenUriRelativeAddress, listenUriMode, parameters);
             }
             return typeof(IDuplexSessionChannel);
         }
     }
     for (int j = 0; j < supportedChannels.Length; j++)
     {
         System.Type type2 = supportedChannels[j];
         if ((type2 == typeof(IInputChannel)) && binding.CanBuildChannelListener<IInputSessionChannel>(parameters))
         {
             if (actuallyCreate)
             {
                 IChannelListener<IInputSessionChannel> inner = binding.BuildChannelListener<IInputSessionChannel>(listenUriBaseAddress, listenUriRelativeAddress, listenUriMode, parameters);
                 result = DatagramAdapter.GetInputListener(inner, throttle, binding);
             }
             return typeof(IInputSessionChannel);
         }
         if ((type2 == typeof(IReplyChannel)) && binding.CanBuildChannelListener<IReplySessionChannel>(parameters))
         {
             if (actuallyCreate)
             {
                 IChannelListener<IReplySessionChannel> listener2 = binding.BuildChannelListener<IReplySessionChannel>(listenUriBaseAddress, listenUriRelativeAddress, listenUriMode, parameters);
                 result = DatagramAdapter.GetReplyListener(listener2, throttle, binding);
             }
             return typeof(IReplySessionChannel);
         }
         if ((supportContextSession && (type2 == typeof(IReplySessionChannel))) && (binding.CanBuildChannelListener<IReplyChannel>(parameters) && (binding.GetProperty<IContextSessionProvider>(parameters) != null)))
         {
             if (actuallyCreate)
             {
                 result = binding.BuildChannelListener<IReplyChannel>(listenUriBaseAddress, listenUriRelativeAddress, listenUriMode, parameters);
             }
             return typeof(IReplyChannel);
         }
     }
     return null;
 }
 public ListenUriInfo(Uri listenUri, ListenUriMode listenUriMode)
 {
     this.listenUri = listenUri;
     this.listenUriMode = listenUriMode;
 }
Example #25
0
        internal static void InitializeServiceHost(ServiceHostBase serviceHost)
        {
            var description = serviceHost.Description;

            if (serviceHost.ImplementedContracts != null && serviceHost.ImplementedContracts.Count > 0)
            {
                EnsureThereAreApplicationEndpoints(description);
            }

            ValidateDescription(serviceHost);

            var stuffPerListenUriInfo           = new Dictionary <ListenUriInfo, StuffPerListenUriInfo>();
            var endpointInfosPerEndpointAddress = new Dictionary <EndpointAddress, Collection <EndpointInfo> >();

            // Ensure ListenUri and group endpoints per ListenUri
            for (int i = 0; i < description.Endpoints.Count; i++)
            {
                ServiceEndpoint endpoint = description.Endpoints[i];

                ListenUriInfo listenUriInfo = GetListenUriInfoForEndpoint(serviceHost, endpoint);
                if (!stuffPerListenUriInfo.ContainsKey(listenUriInfo))
                {
                    stuffPerListenUriInfo.Add(listenUriInfo, new StuffPerListenUriInfo());
                }
                stuffPerListenUriInfo[listenUriInfo].Endpoints.Add(endpoint);
            }

            foreach (KeyValuePair <ListenUriInfo, StuffPerListenUriInfo> stuff in stuffPerListenUriInfo)
            {
                Uri           listenUri               = stuff.Key.ListenUri;
                ListenUriMode listenUriMode           = stuff.Key.ListenUriMode;
                BindingParameterCollection parameters = stuff.Value.Parameters;
                Binding          binding              = stuff.Value.Endpoints[0].Binding;
                EndpointIdentity identity             = stuff.Value.Endpoints[0].Address.Identity;
                // same EndpointAddressTable instance must be shared between channelDispatcher and parameters
                //ThreadSafeMessageFilterTable<EndpointAddress> endpointAddressTable = new ThreadSafeMessageFilterTable<EndpointAddress>();
                //parameters.Add(endpointAddressTable);

                // add service-level binding parameters
                foreach (IServiceBehavior behavior in description.Behaviors)
                {
                    behavior.AddBindingParameters(description, serviceHost, stuff.Value.Endpoints, parameters);
                }
                for (int i = 0; i < stuff.Value.Endpoints.Count; i++)
                {
                    ServiceEndpoint endpoint  = stuff.Value.Endpoints[i];
                    string          viaString = listenUri.AbsoluteUri;

                    // ensure all endpoints with this ListenUriInfo have same binding
                    if (endpoint.Binding != binding)
                    {
                        throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.Format(SR.ABindingInstanceHasAlreadyBeenAssociatedTo1, viaString)));
                    }

                    // ensure all endpoints with this ListenUriInfo have same identity
                    if (!object.Equals(endpoint.Address.Identity, identity))
                    {
                        throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(
                                                                                      SR.Format(SR.SFxWhenMultipleEndpointsShareAListenUriTheyMustHaveSameIdentity, viaString)));
                    }

                    // add binding parameters (endpoint scope and below)
                    AddBindingParametersForSecurityContractInformation(endpoint, parameters);
                    AddBindingParameters(endpoint, parameters);
                }

                List <Type> channelTypes = GetSupportedChannelTypes(stuff.Value);

                var bindingQname      = new XmlQualifiedName(binding.Name, binding.Namespace);
                var channelDispatcher = new ChannelDispatcher(listenUri, binding, bindingQname.ToString(), binding, channelTypes);
                //channelDispatcher.SetEndpointAddressTable(endpointAddressTable);
                stuff.Value.ChannelDispatcher = channelDispatcher;

                for (int i = 0; i < stuff.Value.Endpoints.Count; i++)
                {
                    ServiceEndpoint endpoint  = stuff.Value.Endpoints[i];
                    string          viaString = listenUri.AbsoluteUri;

                    //EndpointFilterProvider provider = new EndpointFilterProvider();
                    EndpointDispatcher dispatcher = BuildEndpointDispatcher(description, endpoint);

                    if (!endpointInfosPerEndpointAddress.ContainsKey(endpoint.Address))
                    {
                        endpointInfosPerEndpointAddress.Add(endpoint.Address, new Collection <EndpointInfo>());
                    }

                    endpointInfosPerEndpointAddress[endpoint.Address].Add(new EndpointInfo(endpoint, dispatcher, /*provider*/ null));
                    channelDispatcher.Endpoints.Add(dispatcher);
                } // end foreach "endpoint"

                serviceHost.ChannelDispatchers.Add(channelDispatcher);
            } // end foreach "ListenUri/ChannelDispatcher" group

            // run service behaviors
            for (int i = 0; i < description.Behaviors.Count; i++)
            {
                IServiceBehavior serviceBehavior = description.Behaviors[i];
                serviceBehavior.ApplyDispatchBehavior(description, serviceHost);
            }

            foreach (KeyValuePair <ListenUriInfo, StuffPerListenUriInfo> stuff in stuffPerListenUriInfo)
            {
                for (int i = 0; i < stuff.Value.Endpoints.Count; i++)
                {
                    ServiceEndpoint endpoint = stuff.Value.Endpoints[i];
                    // rediscover which dispatcher goes with this endpoint
                    Collection <EndpointInfo> infos = endpointInfosPerEndpointAddress[endpoint.Address];
                    EndpointInfo info = null;
                    foreach (EndpointInfo ei in infos)
                    {
                        if (ei.Endpoint == endpoint)
                        {
                            info = ei;
                            break;
                        }
                    }
                    EndpointDispatcher dispatcher = info.EndpointDispatcher;
                    // run contract behaviors
                    for (int k = 0; k < endpoint.Contract.Behaviors.Count; k++)
                    {
                        IContractBehavior behavior = endpoint.Contract.Behaviors[k];
                        behavior.ApplyDispatchBehavior(endpoint.Contract, endpoint, dispatcher.DispatchRuntime);
                    }
                    // run endpoint behaviors
                    ApplyBindingInformationFromEndpointToDispatcher(endpoint, dispatcher);
                    for (int j = 0; j < endpoint.Behaviors.Count; j++)
                    {
                        IEndpointBehavior eb = endpoint.Behaviors[j];
                        eb.ApplyDispatchBehavior(endpoint, dispatcher);
                    }
                    // run operation behaviors
                    BindOperations(endpoint.Contract, null, dispatcher.DispatchRuntime);
                }
            }

            EnsureRequiredRuntimeProperties(endpointInfosPerEndpointAddress);

            // Warn about obvious demux conflicts
            foreach (Collection <EndpointInfo> endpointInfos in endpointInfosPerEndpointAddress.Values)
            {
                // all elements of endpointInfos share the same Address (and thus EndpointListener.AddressFilter)
                if (endpointInfos.Count > 1)
                {
                    for (int i = 0; i < endpointInfos.Count; i++)
                    {
                        for (int j = i + 1; j < endpointInfos.Count; j++)
                        {
                            // if not same ListenUri, won't conflict
                            // if not same ChannelType, may not conflict (some transports demux based on this)
                            // if they share a ChannelDispatcher, this means same ListenUri and same ChannelType
                            if (endpointInfos[i].EndpointDispatcher.ChannelDispatcher ==
                                endpointInfos[j].EndpointDispatcher.ChannelDispatcher)
                            {
                                EndpointFilterProvider iProvider = endpointInfos[i].FilterProvider;
                                EndpointFilterProvider jProvider = endpointInfos[j].FilterProvider;
                                // if not default EndpointFilterProvider, we won't try to throw, you're on your own
                                string commonAction;
                                if (iProvider != null && jProvider != null &&
                                    HaveCommonInitiatingActions(iProvider, jProvider, out commonAction))
                                {
                                    // you will definitely get a MultipleFiltersMatchedException at runtime,
                                    // so let's go ahead and throw now
                                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(
                                              new InvalidOperationException(
                                                  SR.Format(SR.SFxDuplicateInitiatingActionAtSameVia, endpointInfos[i].Endpoint.ListenUri, commonAction)));
                                }
                            }
                        }
                    }
                }
            }
        }
 static internal Type MaybeCreateListener(bool actuallyCreate, Type[] supportedChannels,
                                          Binding binding, BindingParameterCollection parameters,
                                          Uri listenUriBaseAddress, string listenUriRelativeAddress,
                                          ListenUriMode listenUriMode, ServiceThrottle throttle,
                                          out IChannelListener result)
 {
     return MaybeCreateListener(actuallyCreate, supportedChannels, binding, parameters, listenUriBaseAddress, listenUriRelativeAddress, listenUriMode, throttle,
         out result, false);
 }
Example #27
0
 public ListenUriInfo(Uri listenUri, ListenUriMode listenUriMode)
 {
     this.listenUri     = listenUri;
     this.listenUriMode = listenUriMode;
 }
Example #28
0
 public ListenUriInfo(Uri listenUri, ListenUriMode listenUriMode)
 {
     _listenUri = listenUri;
     _listenUriMode = listenUriMode;
 }
Example #29
0
        static Type MaybeCreateListener(bool actuallyCreate, Type[] supportedChannels,
                                        Binding binding, BindingParameterCollection parameters,
                                        Uri listenUriBaseAddress, string listenUriRelativeAddress,
                                        ListenUriMode listenUriMode,
                                        out IChannelListener result)
        {
            // if actuallyCreate is true, then this behaves like CreateListener()
            // else this behaves like CanCreateListener()
            // result is channel type that was (would be) created, null if can't create
            //
            // Ugly API helps refactor common code in these two similar-but-different methods

            result = null;

            for (int i = 0; i < supportedChannels.Length; i++)
            {
                Type channelType = supportedChannels[i];

                if (channelType == typeof(IInputChannel))
                {
                    if (binding.CanBuildChannelListener <IInputChannel>(parameters))
                    {
                        if (actuallyCreate)
                        {
                            result = binding.BuildChannelListener <IInputChannel>(listenUriBaseAddress, listenUriRelativeAddress, listenUriMode, parameters);
                        }
                        return(typeof(IInputChannel));
                    }
                }
                if (channelType == typeof(IReplyChannel))
                {
                    if (binding.CanBuildChannelListener <IReplyChannel>(parameters))
                    {
                        if (actuallyCreate)
                        {
                            result = binding.BuildChannelListener <IReplyChannel>(listenUriBaseAddress, listenUriRelativeAddress, listenUriMode, parameters);
                        }
                        return(typeof(IReplyChannel));
                    }
                }
                if (channelType == typeof(IDuplexChannel))
                {
                    if (binding.CanBuildChannelListener <IDuplexChannel>(parameters))
                    {
                        if (actuallyCreate)
                        {
                            result = binding.BuildChannelListener <IDuplexChannel>(listenUriBaseAddress, listenUriRelativeAddress, listenUriMode, parameters);
                        }
                        return(typeof(IDuplexChannel));
                    }
                }
                if (channelType == typeof(IInputSessionChannel))
                {
                    if (binding.CanBuildChannelListener <IInputSessionChannel>(parameters))
                    {
                        if (actuallyCreate)
                        {
                            result = binding.BuildChannelListener <IInputSessionChannel>(listenUriBaseAddress, listenUriRelativeAddress, listenUriMode, parameters);
                        }
                        return(typeof(IInputSessionChannel));
                    }
                }
                if (channelType == typeof(IReplySessionChannel))
                {
                    if (binding.CanBuildChannelListener <IReplySessionChannel>(parameters))
                    {
                        if (actuallyCreate)
                        {
                            result = binding.BuildChannelListener <IReplySessionChannel>(listenUriBaseAddress, listenUriRelativeAddress, listenUriMode, parameters);
                        }
                        return(typeof(IReplySessionChannel));
                    }
                }
                if (channelType == typeof(IDuplexSessionChannel))
                {
                    if (binding.CanBuildChannelListener <IDuplexSessionChannel>(parameters))
                    {
                        if (actuallyCreate)
                        {
                            result = binding.BuildChannelListener <IDuplexSessionChannel>(listenUriBaseAddress, listenUriRelativeAddress, listenUriMode, parameters);
                        }
                        return(typeof(IDuplexSessionChannel));
                    }
                }
            }

            return(null);
        }