InitializeFrom() private method

private InitializeFrom ( UdpTransportBindingElement udpTransportBindingElement, TextMessageEncodingBindingElement textMessageEncodingBindingElement, ReliableSessionBindingElement reliableSessionBindingElement, CompositeDuplexBindingElement compositeDuplexBindingElement ) : void
udpTransportBindingElement UdpTransportBindingElement
textMessageEncodingBindingElement TextMessageEncodingBindingElement
reliableSessionBindingElement ReliableSessionBindingElement
compositeDuplexBindingElement CompositeDuplexBindingElement
return void
Example #1
0
        //try to create a SampleProfileUdpBinding from the collection of BindingElement
        //returns true if it is possible, with the resulting binding.
        public static bool TryCreate(BindingElementCollection elements, out Binding binding)
        {
            binding = null;
            if (elements.Count > 4)
            {
                return false;
            }

            ReliableSessionBindingElement reliableSessionBindingElement = null;
            CompositeDuplexBindingElement compositeDuplexBindingElement = null;
            TextMessageEncodingBindingElement textMessageEncodingBindingElement = null;
            UdpTransportBindingElement udpTransportBindingElement = null;

            foreach (BindingElement element in elements)
            {
                if (element is CompositeDuplexBindingElement)
                {
                    compositeDuplexBindingElement = element as CompositeDuplexBindingElement;
                }
                else if (element is TransportBindingElement)
                {
                    udpTransportBindingElement = element as UdpTransportBindingElement;
                }
                else if (element is TextMessageEncodingBindingElement)
                {
                    textMessageEncodingBindingElement = element as TextMessageEncodingBindingElement;
                }
                else if (element is ReliableSessionBindingElement)
                {
                    reliableSessionBindingElement = element as ReliableSessionBindingElement;
                }
                else
                {
                    return false;
                }
            }

            if (udpTransportBindingElement == null)
            {
                return false;
            }
            if (textMessageEncodingBindingElement == null)
            {
                return false;
            }

            if (((reliableSessionBindingElement != null) && (compositeDuplexBindingElement == null))
                || ((reliableSessionBindingElement == null) && (compositeDuplexBindingElement != null)))
            {
                return false;
            }

            NetUdpBinding sampleProfileUdpBinding = new NetUdpBinding();
            sampleProfileUdpBinding.InitializeFrom(udpTransportBindingElement, textMessageEncodingBindingElement,
                                            reliableSessionBindingElement, compositeDuplexBindingElement);
            if (!sampleProfileUdpBinding.IsBindingElementsMatch(udpTransportBindingElement, textMessageEncodingBindingElement,
                                                         reliableSessionBindingElement, compositeDuplexBindingElement))
            {
                return false;
            }

            binding = sampleProfileUdpBinding;
            return true;
        }
Example #2
0
        //try to create a SampleProfileUdpBinding from the collection of BindingElement
        //returns true if it is possible, with the resulting binding.
        public static bool TryCreate(BindingElementCollection elements, out Binding binding)
        {
            binding = null;
            if (elements.Count > 4)
            {
                return(false);
            }

            ReliableSessionBindingElement     reliableSessionBindingElement     = null;
            CompositeDuplexBindingElement     compositeDuplexBindingElement     = null;
            TextMessageEncodingBindingElement textMessageEncodingBindingElement = null;
            UdpTransportBindingElement        udpTransportBindingElement        = null;

            foreach (BindingElement element in elements)
            {
                if (element is CompositeDuplexBindingElement)
                {
                    compositeDuplexBindingElement = element as CompositeDuplexBindingElement;
                }
                else if (element is TransportBindingElement)
                {
                    udpTransportBindingElement = element as UdpTransportBindingElement;
                }
                else if (element is TextMessageEncodingBindingElement)
                {
                    textMessageEncodingBindingElement = element as TextMessageEncodingBindingElement;
                }
                else if (element is ReliableSessionBindingElement)
                {
                    reliableSessionBindingElement = element as ReliableSessionBindingElement;
                }
                else
                {
                    return(false);
                }
            }

            if (udpTransportBindingElement == null)
            {
                return(false);
            }
            if (textMessageEncodingBindingElement == null)
            {
                return(false);
            }

            if (((reliableSessionBindingElement != null) && (compositeDuplexBindingElement == null)) ||
                ((reliableSessionBindingElement == null) && (compositeDuplexBindingElement != null)))
            {
                return(false);
            }

            NetUdpBinding sampleProfileUdpBinding = new NetUdpBinding();

            sampleProfileUdpBinding.InitializeFrom(udpTransportBindingElement, textMessageEncodingBindingElement,
                                                   reliableSessionBindingElement, compositeDuplexBindingElement);
            if (!sampleProfileUdpBinding.IsBindingElementsMatch(udpTransportBindingElement, textMessageEncodingBindingElement,
                                                                reliableSessionBindingElement, compositeDuplexBindingElement))
            {
                return(false);
            }

            binding = sampleProfileUdpBinding;
            return(true);
        }