void IWsdlImportExtension.ImportEndpoint(WsdlImporter importer, WsdlEndpointConversionContext context)
        {
            if (context == null)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("context");
            }

#pragma warning suppress 56506 // [....], these properties cannot be null in this context
            if (context.Endpoint.Binding == null)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("context.Endpoint.Binding");
            }

            BindingElementCollection bindingElements = GetBindingElements(context);
            MessageEncodingBindingElement messageEncodingBindingElement = bindingElements.Find<MessageEncodingBindingElement>();
            TextMessageEncodingBindingElement textEncodingBindingElement = messageEncodingBindingElement as TextMessageEncodingBindingElement;

            if (messageEncodingBindingElement != null)
            {
                Type elementType = messageEncodingBindingElement.GetType();
                if (elementType != typeof(TextMessageEncodingBindingElement)
                    && elementType != typeof(BinaryMessageEncodingBindingElement)
                    && elementType != typeof(MtomMessageEncodingBindingElement))
                    return;
            }

            EnsureMessageEncoding(context, messageEncodingBindingElement);

            foreach (OperationBinding wsdlOperationBinding in context.WsdlBinding.Operations)
            {
                OperationDescription operation = context.GetOperationDescription(wsdlOperationBinding);

                for (int i = 0; i < operation.Messages.Count; i++)
                {
                    MessageDescription message = operation.Messages[i];
                    MessageBinding wsdlMessageBinding = context.GetMessageBinding(message);
                    ImportMessageSoapAction(context.ContractConversionContext, message, wsdlMessageBinding, i != 0 /*isResponse*/);
                }

                foreach (FaultDescription fault in operation.Faults)
                {
                    FaultBinding wsdlFaultBinding = context.GetFaultBinding(fault);
                    if (wsdlFaultBinding != null)
                    {
                        ImportFaultSoapAction(context.ContractConversionContext, fault, wsdlFaultBinding);
                    }
                }
            }

        }
            internal void AttachPolicy(ServiceEndpoint endpoint, WsdlEndpointConversionContext endpointContext, PolicyConversionContext policyContext)
            {
                SortedList<string, string> policyKeys = new SortedList<string, string>();
                NamingHelper.DoesNameExist policyKeyIsUnique
                    = delegate(string name, object nameCollection)
                    {
                        return policyKeys.ContainsKey(name);
                    };

                string key, keyBase;
                ICollection<XmlElement> assertions;

                WsdlNS.ServiceDescription policyWsdl = endpointContext.WsdlBinding.ServiceDescription;

                assertions = policyContext.GetBindingAssertions();

                // Add [wsdl:Binding] level Policy
                WsdlNS.Binding wsdlBinding = endpointContext.WsdlBinding;
                if (assertions.Count > 0)
                {
                    keyBase = CreateBindingPolicyKey(wsdlBinding);
                    key = NamingHelper.GetUniqueName(keyBase, policyKeyIsUnique, null);
                    policyKeys.Add(key, key);
                    AttachItemPolicy(assertions, key, policyWsdl, wsdlBinding);
                }

                foreach (OperationDescription operation in endpoint.Contract.Operations)
                {
                    if (!WsdlExporter.OperationIsExportable(operation))
                    {
                        continue;
                    }

                    assertions = policyContext.GetOperationBindingAssertions(operation);

                    // Add [wsdl:Binding/wsdl:operation] policy
                    if (assertions.Count > 0)
                    {
                        WsdlNS.OperationBinding wsdlOperationBinding = endpointContext.GetOperationBinding(operation);
                        keyBase = CreateOperationBindingPolicyKey(wsdlOperationBinding);
                        key = NamingHelper.GetUniqueName(keyBase, policyKeyIsUnique, null);
                        policyKeys.Add(key, key);
                        AttachItemPolicy(assertions, key, policyWsdl, wsdlOperationBinding);
                    }

                    //
                    // Add [wsdl:Binding/wsdl:operation] child policy
                    //

                    foreach (MessageDescription message in operation.Messages)
                    {
                        assertions = policyContext.GetMessageBindingAssertions(message);

                        // Add [wsdl:Binding/wsdl:operation/wsdl:(input, output, message)] policy
                        if (assertions.Count > 0)
                        {
                            WsdlNS.MessageBinding wsdlMessageBinding = endpointContext.GetMessageBinding(message);
                            keyBase = CreateMessageBindingPolicyKey(wsdlMessageBinding, message.Direction);
                            key = NamingHelper.GetUniqueName(keyBase, policyKeyIsUnique, null);
                            policyKeys.Add(key, key);
                            AttachItemPolicy(assertions, key, policyWsdl, wsdlMessageBinding);
                        }
                    }

                    foreach (FaultDescription fault in operation.Faults)
                    {
                        assertions = policyContext.GetFaultBindingAssertions(fault);

                        // Add [wsdl:Binding/wsdl:operation/wsdl:fault] policy
                        if (assertions.Count > 0)
                        {
                            WsdlNS.FaultBinding wsdlFaultBinding = endpointContext.GetFaultBinding(fault);
                            keyBase = CreateFaultBindingPolicyKey(wsdlFaultBinding);
                            key = NamingHelper.GetUniqueName(keyBase, policyKeyIsUnique, null);
                            policyKeys.Add(key, key);
                            AttachItemPolicy(assertions, key, policyWsdl, wsdlFaultBinding);
                        }
                    }
                }
            }
 void IWsdlImportExtension.ImportEndpoint(WsdlImporter importer, WsdlEndpointConversionContext context)
 {
     if (context == null)
     {
         throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("context");
     }
     if (context.Endpoint.Binding == null)
     {
         throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("context.Endpoint.Binding");
     }
     MessageEncodingBindingElement encodingBindingElement = GetBindingElements(context).Find<MessageEncodingBindingElement>();
     if (encodingBindingElement != null)
     {
         System.Type type = encodingBindingElement.GetType();
         if (((type != typeof(TextMessageEncodingBindingElement)) && (type != typeof(BinaryMessageEncodingBindingElement))) && (type != typeof(MtomMessageEncodingBindingElement)))
         {
             return;
         }
     }
     EnsureMessageEncoding(context, encodingBindingElement);
     foreach (OperationBinding binding in context.WsdlBinding.Operations)
     {
         OperationDescription operationDescription = context.GetOperationDescription(binding);
         for (int i = 0; i < operationDescription.Messages.Count; i++)
         {
             MessageDescription message = operationDescription.Messages[i];
             MessageBinding messageBinding = context.GetMessageBinding(message);
             ImportMessageSoapAction(context.ContractConversionContext, message, messageBinding, i != 0);
         }
         foreach (FaultDescription description3 in operationDescription.Faults)
         {
             FaultBinding faultBinding = context.GetFaultBinding(description3);
             if (faultBinding != null)
             {
                 ImportFaultSoapAction(context.ContractConversionContext, description3, faultBinding);
             }
         }
     }
 }
 internal void AttachPolicy(ServiceEndpoint endpoint, WsdlEndpointConversionContext endpointContext, PolicyConversionContext policyContext)
 {
     string str;
     SortedList<string, string> policyKeys = new SortedList<string, string>();
     NamingHelper.DoesNameExist doesNameExist = (name, nameCollection) => policyKeys.ContainsKey(name);
     System.Web.Services.Description.ServiceDescription serviceDescription = endpointContext.WsdlBinding.ServiceDescription;
     ICollection<XmlElement> bindingAssertions = policyContext.GetBindingAssertions();
     System.Web.Services.Description.Binding wsdlBinding = endpointContext.WsdlBinding;
     if (bindingAssertions.Count > 0)
     {
         str = NamingHelper.GetUniqueName(CreateBindingPolicyKey(wsdlBinding), doesNameExist, null);
         policyKeys.Add(str, str);
         this.AttachItemPolicy(bindingAssertions, str, serviceDescription, wsdlBinding);
     }
     foreach (OperationDescription description2 in endpoint.Contract.Operations)
     {
         if (WsdlExporter.OperationIsExportable(description2))
         {
             bindingAssertions = policyContext.GetOperationBindingAssertions(description2);
             if (bindingAssertions.Count > 0)
             {
                 OperationBinding operationBinding = endpointContext.GetOperationBinding(description2);
                 str = NamingHelper.GetUniqueName(CreateOperationBindingPolicyKey(operationBinding), doesNameExist, null);
                 policyKeys.Add(str, str);
                 this.AttachItemPolicy(bindingAssertions, str, serviceDescription, operationBinding);
             }
             foreach (MessageDescription description3 in description2.Messages)
             {
                 bindingAssertions = policyContext.GetMessageBindingAssertions(description3);
                 if (bindingAssertions.Count > 0)
                 {
                     MessageBinding messageBinding = endpointContext.GetMessageBinding(description3);
                     str = NamingHelper.GetUniqueName(CreateMessageBindingPolicyKey(messageBinding, description3.Direction), doesNameExist, null);
                     policyKeys.Add(str, str);
                     this.AttachItemPolicy(bindingAssertions, str, serviceDescription, messageBinding);
                 }
             }
             foreach (FaultDescription description4 in description2.Faults)
             {
                 bindingAssertions = policyContext.GetFaultBindingAssertions(description4);
                 if (bindingAssertions.Count > 0)
                 {
                     FaultBinding faultBinding = endpointContext.GetFaultBinding(description4);
                     str = NamingHelper.GetUniqueName(CreateFaultBindingPolicyKey(faultBinding), doesNameExist, null);
                     policyKeys.Add(str, str);
                     this.AttachItemPolicy(bindingAssertions, str, serviceDescription, faultBinding);
                 }
             }
         }
     }
 }