public static void EnableAllMexEndpoints(this ServiceHost host)
        {
            // Add a ServiceMetadataBehavior object to the ServiceDescription.Behaviors collection (or the <serviceMetadata> element in an application configuration file) to enable or disable the publication of service metadata. However, adding the behavior to a service is not sufficient to enable metadata publication:
            //      To enable WS-Transfer GET metadata retrieval, you must also add an endpoint to your service in which the contract is IMetadataExchange. For an example, see How To: Publish Metadata for a Service Using Code. The IMetadataExchange endpoint can be configured as can any other endpoint.
            //      To enable HTTP GET metadata retrieval, set the HttpGetEnabled property to true. For more information about the address of HTTP GET metadata, see HttpGetEnabled.
            host.Description.Behaviors.Add(new ServiceMetadataBehavior());

            foreach (Uri baseAddress in host.BaseAddresses)
            {
                Binding binding = null;

                if (baseAddress.Scheme == "net.tcp")
                {
                    binding = MetadataExchangeBindings.CreateMexTcpBinding();
                }
                if (baseAddress.Scheme == "net.pipe")
                {
                    binding = MetadataExchangeBindings.CreateMexNamedPipeBinding();
                }
                if (baseAddress.Scheme == "http")
                {
                    binding = MetadataExchangeBindings.CreateMexHttpBinding();
                }
                if (baseAddress.Scheme == "https")
                {
                    binding = MetadataExchangeBindings.CreateMexHttpsBinding();
                }

                if (binding != null)
                {
                    host.AddServiceEndpoint(typeof(IMetadataExchange), binding, "MEX");
                }
            }
        }
        public static ServiceHost AddBasicHttpEndpoint(this ServiceHost serviceHost, Type contractType, Uri endPointAddress)
        {
            if (endPointAddress == null)
                return serviceHost;

            if ("http".Equals(endPointAddress.Scheme))
            {
                serviceHost.AddServiceEndpoint(contractType,
                    new BasicHttpBinding(), endPointAddress);
            }

            return serviceHost;
        }
        public static ServiceHost AddHttpsEndpoint(this ServiceHost serviceHost, Type contractType, Uri endPointAddress)
        {
            if (endPointAddress == null)
                return serviceHost;

            if ("https".Equals(endPointAddress.Scheme))
            {
                var wsb = new WSHttpBinding();
                wsb.Security.Mode = SecurityMode.Transport;
                serviceHost.AddServiceEndpoint(contractType,
                    wsb, endPointAddress);
            }

            return serviceHost;
        }
      internal static void AddServiceBusDefaultEndpoints(this ServiceHost host,Uri[] baseAddresses)
      {
         Debug.Assert(baseAddresses.Any(address=>address.Scheme == "sb"));

         Type[] contracts = GetServiceContracts(host.Description.ServiceType);
         Binding binding = new NetTcpRelayBinding();

         foreach(Uri baseAddress in baseAddresses)
         {
            if(baseAddress.Scheme != "sb")
            {
               continue;
            }           

            foreach(Type contract in contracts)
            {
               string address = baseAddress.AbsoluteUri;

               if(address.EndsWith("/") == false)
               {
                  address += "/";
               }  
               address += contract.Name;
               host.AddServiceEndpoint(contract,binding,address);
            }
         }
      }