void ExportEndpoint(ServiceEndpoint endpoint, XmlQualifiedName wsdlServiceQName, BindingParameterCollection bindingParameters)
        {
            if (endpoint.Binding == null)
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentException(SR.GetString(SR.EndpointsMustHaveAValidBinding1, endpoint.Name)));

            EndpointDictionaryKey endpointKey = new EndpointDictionaryKey(endpoint, wsdlServiceQName);

            try
            {
                if (exportedEndpoints.ContainsKey(endpointKey))
                    return;

                this.ExportContract(endpoint.Contract);

                // Retreive Conversion Context for Contract;
                // Note: Contract must have already been exported at this point.
                WsdlContractConversionContext contractContext = this.exportedContracts[endpoint.Contract];


                bool newWsdlBinding, bindingNameWasUniquified;
                WsdlNS.Port wsdlPort;
                WsdlNS.Binding wsdlBinding;
                wsdlBinding = CreateWsdlBindingAndPort(endpoint, wsdlServiceQName, out wsdlPort, out newWsdlBinding, out bindingNameWasUniquified);


                if (!newWsdlBinding && wsdlPort == null)
                    return;

                // Create an Endpoint conversion context based on 
                // the contract's conversion context (reuse contract correlation information)
                WsdlEndpointConversionContext endpointContext;
                if (newWsdlBinding)
                {
                    endpointContext = new WsdlEndpointConversionContext(contractContext, endpoint, wsdlBinding, wsdlPort);

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

                        WsdlNS.OperationBinding wsdlOperationBinding = CreateWsdlOperationBinding(endpoint.Contract, operation);
                        wsdlBinding.Operations.Add(wsdlOperationBinding);

                        endpointContext.AddOperationBinding(operation, wsdlOperationBinding);

                        foreach (MessageDescription message in operation.Messages)
                        {
                            WsdlNS.MessageBinding wsdlMessageBinding = CreateWsdlMessageBinding(message, endpoint.Binding, wsdlOperationBinding);
                            endpointContext.AddMessageBinding(message, wsdlMessageBinding);
                        }

                        foreach (FaultDescription fault in operation.Faults)
                        {
                            WsdlNS.FaultBinding wsdlFaultBinding = CreateWsdlFaultBinding(fault, endpoint.Binding, wsdlOperationBinding);
                            endpointContext.AddFaultBinding(fault, wsdlFaultBinding);
                        }
                    }

                    // CSDMain 180381:  Added internal functionality for passing BindingParameters into the ExportPolicy process via PolicyConversionContext.
                    // However, in order to not change existing behavior, we only call the internal ExportPolicy method which accepts BindingParameters if they are not null
                    // (non-null binding parameters can only be passed in via internal code paths).  Otherwise, we call the existing ExportPolicy method, just like before.
                    PolicyConversionContext policyContext;
                    if (bindingParameters == null)
                    {
                        policyContext = this.ExportPolicy(endpoint);
                    }
                    else
                    {
                        policyContext = this.ExportPolicy(endpoint, bindingParameters);
                    }
                    // consider factoring this out of wsdl exporter
                    new WSPolicyAttachmentHelper(this.PolicyVersion).AttachPolicy(endpoint, endpointContext, policyContext);
                    exportedBindings.Add(new BindingDictionaryKey(endpoint.Contract, endpoint.Binding), endpointContext);
                }
                else
                {
                    endpointContext = new WsdlEndpointConversionContext(exportedBindings[new BindingDictionaryKey(endpoint.Contract, endpoint.Binding)], endpoint, wsdlPort);
                }

                CallExportEndpoint(endpointContext);
                exportedEndpoints.Add(endpointKey, endpoint);
                if (bindingNameWasUniquified)
                    Errors.Add(new MetadataConversionError(SR.GetString(SR.WarnDuplicateBindingQNameNameOnExport, endpoint.Binding.Name, endpoint.Binding.Namespace, endpoint.Contract.Name), true /*isWarning*/));
            }
            catch
            {
                isFaulted = true;
                throw;
            }
        }
 private void ExportEndpoint(ServiceEndpoint endpoint, XmlQualifiedName wsdlServiceQName)
 {
     if (endpoint.Binding == null)
     {
         throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentException(System.ServiceModel.SR.GetString("EndpointsMustHaveAValidBinding1", new object[] { endpoint.Name })));
     }
     EndpointDictionaryKey key = new EndpointDictionaryKey(endpoint, wsdlServiceQName);
     try
     {
         if (!this.exportedEndpoints.ContainsKey(key))
         {
             bool flag;
             bool flag2;
             Port port;
             this.ExportContract(endpoint.Contract);
             WsdlContractConversionContext contractContext = this.exportedContracts[endpoint.Contract];
             System.Web.Services.Description.Binding wsdlBinding = this.CreateWsdlBindingAndPort(endpoint, wsdlServiceQName, out port, out flag, out flag2);
             if (flag || (port != null))
             {
                 WsdlEndpointConversionContext context2;
                 if (flag)
                 {
                     context2 = new WsdlEndpointConversionContext(contractContext, endpoint, wsdlBinding, port);
                     foreach (OperationDescription description in endpoint.Contract.Operations)
                     {
                         if (OperationIsExportable(description))
                         {
                             OperationBinding bindingOperation = this.CreateWsdlOperationBinding(endpoint.Contract, description);
                             wsdlBinding.Operations.Add(bindingOperation);
                             context2.AddOperationBinding(description, bindingOperation);
                             foreach (MessageDescription description2 in description.Messages)
                             {
                                 MessageBinding wsdlMessageBinding = this.CreateWsdlMessageBinding(description2, endpoint.Binding, bindingOperation);
                                 context2.AddMessageBinding(description2, wsdlMessageBinding);
                             }
                             foreach (FaultDescription description3 in description.Faults)
                             {
                                 FaultBinding wsdlFaultBinding = this.CreateWsdlFaultBinding(description3, endpoint.Binding, bindingOperation);
                                 context2.AddFaultBinding(description3, wsdlFaultBinding);
                             }
                         }
                     }
                     PolicyConversionContext policyContext = base.ExportPolicy(endpoint);
                     new WSPolicyAttachmentHelper(base.PolicyVersion).AttachPolicy(endpoint, context2, policyContext);
                     this.exportedBindings.Add(new BindingDictionaryKey(endpoint.Contract, endpoint.Binding), context2);
                 }
                 else
                 {
                     context2 = new WsdlEndpointConversionContext(this.exportedBindings[new BindingDictionaryKey(endpoint.Contract, endpoint.Binding)], endpoint, port);
                 }
                 this.CallExportEndpoint(context2);
                 this.exportedEndpoints.Add(key, endpoint);
                 if (flag2)
                 {
                     base.Errors.Add(new MetadataConversionError(System.ServiceModel.SR.GetString("WarnDuplicateBindingQNameNameOnExport", new object[] { endpoint.Binding.Name, endpoint.Binding.Namespace, endpoint.Contract.Name }), true));
                 }
             }
         }
     }
     catch
     {
         this.isFaulted = true;
         throw;
     }
 }