protected UnrecognizedAssertionsBindingElement(UnrecognizedAssertionsBindingElement elementToBeCloned) : base(elementToBeCloned)
 {
     this.wsdlBinding         = elementToBeCloned.wsdlBinding;
     this.bindingAsserions    = elementToBeCloned.bindingAsserions;
     this.operationAssertions = elementToBeCloned.operationAssertions;
     this.messageAssertions   = elementToBeCloned.messageAssertions;
 }
 protected UnrecognizedAssertionsBindingElement(UnrecognizedAssertionsBindingElement elementToBeCloned)
     : base(elementToBeCloned)
 {
     _wsdlBinding         = elementToBeCloned._wsdlBinding;
     _bindingAsserions    = elementToBeCloned._bindingAsserions;
     _operationAssertions = elementToBeCloned._operationAssertions;
     _messageAssertions   = elementToBeCloned._messageAssertions;
 }
        public void ImportEndpoint(WsdlImporter importer, WsdlEndpointConversionContext context)
        {
            if (context == null)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("context");
            }
            if (context.Endpoint == null)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("context.Endpoint");
            }
            if (context.Endpoint.Binding == null)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("context.Endpoint.Binding");
            }

            // Try to post-process the unrecognized RequireHttpCookie assertion to augment the AllowCookies value
            // of HttpTransportBindingElement

            CustomBinding customBinding = context.Endpoint.Binding as CustomBinding;

            if (customBinding != null)
            {
                UnrecognizedAssertionsBindingElement unrecognized = null;
                unrecognized = customBinding.Elements.Find <UnrecognizedAssertionsBindingElement>();
                HttpTransportBindingElement http = null;
                if (unrecognized != null)
                {
                    XmlElement httpUseCookieAssertion = null;
                    if (ContextBindingElementPolicy.TryGetHttpUseCookieAssertion(unrecognized.BindingAsserions, out httpUseCookieAssertion))
                    {
                        foreach (BindingElement element in customBinding.Elements)
                        {
                            http = element as HttpTransportBindingElement;
                            if (http != null)
                            {
                                http.AllowCookies = true;
                                unrecognized.BindingAsserions.Remove(httpUseCookieAssertion);
                                if (unrecognized.BindingAsserions.Count == 0)
                                {
                                    customBinding.Elements.Remove(unrecognized);
                                }
                                break;
                            }
                        }
                    }
                }

                // Try to upgrade to standard binding

                BindingElementCollection bindingElements = customBinding.CreateBindingElements();
                Binding binding;
                if (!WSHttpContextBinding.TryCreate(bindingElements, out binding) &&
                    !NetTcpContextBinding.TryCreate(bindingElements, out binding))
                {
                    // Work around BasicHttpBinding.TryCreate insensitivity to HttpTransportBindingElement.AllowCookies value

                    if (http == null)
                    {
                        foreach (BindingElement bindingElement in bindingElements)
                        {
                            http = bindingElement as HttpTransportBindingElement;
                            if (http != null)
                            {
                                break;
                            }
                        }
                    }
                    if (http != null && http.AllowCookies)
                    {
                        http.AllowCookies = false;
                        if (BasicHttpBinding.TryCreate(bindingElements, out binding))
                        {
                            ((BasicHttpBinding)binding).AllowCookies = true;
                        }
                    }
                }

                if (binding != null)
                {
                    binding.Name             = context.Endpoint.Binding.Name;
                    binding.Namespace        = context.Endpoint.Binding.Namespace;
                    context.Endpoint.Binding = binding;
                }
            }
        }
        public void ImportEndpoint(WsdlImporter importer, WsdlEndpointConversionContext context)
        {
            if (context == null)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("context");
            }
            if (context.Endpoint == null)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("context.Endpoint");
            }
            if (context.Endpoint.Binding == null)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("context.Endpoint.Binding");
            }
            CustomBinding binding = context.Endpoint.Binding as CustomBinding;

            if (binding != null)
            {
                System.ServiceModel.Channels.Binding binding2;
                UnrecognizedAssertionsBindingElement item = null;
                item = binding.Elements.Find <UnrecognizedAssertionsBindingElement>();
                HttpTransportBindingElement element2 = null;
                if (item != null)
                {
                    XmlElement httpUseCookieAssertion = null;
                    if (ContextBindingElementPolicy.TryGetHttpUseCookieAssertion(item.BindingAsserions, out httpUseCookieAssertion))
                    {
                        foreach (BindingElement element4 in binding.Elements)
                        {
                            element2 = element4 as HttpTransportBindingElement;
                            if (element2 != null)
                            {
                                element2.AllowCookies = true;
                                item.BindingAsserions.Remove(httpUseCookieAssertion);
                                if (item.BindingAsserions.Count == 0)
                                {
                                    binding.Elements.Remove(item);
                                }
                                break;
                            }
                        }
                    }
                }
                BindingElementCollection bindingElements = binding.CreateBindingElements();
                if (!WSHttpContextBinding.TryCreate(bindingElements, out binding2) && !NetTcpContextBinding.TryCreate(bindingElements, out binding2))
                {
                    if (element2 == null)
                    {
                        foreach (BindingElement element5 in bindingElements)
                        {
                            element2 = element5 as HttpTransportBindingElement;
                            if (element2 != null)
                            {
                                break;
                            }
                        }
                    }
                    if ((element2 != null) && element2.AllowCookies)
                    {
                        element2.AllowCookies = false;
                        if (BasicHttpBinding.TryCreate(bindingElements, out binding2))
                        {
                            ((BasicHttpBinding)binding2).AllowCookies = true;
                        }
                    }
                }
                if (binding2 != null)
                {
                    binding2.Name            = context.Endpoint.Binding.Name;
                    binding2.Namespace       = context.Endpoint.Binding.Namespace;
                    context.Endpoint.Binding = binding2;
                }
            }
        }