protected override void OnStart(string[] args)
    {
        BasicHttpBinding binding = new BasicHttpBinding();

        binding.Security.Mode = BasicHttpSecurityMode.Transport;
        binding.Security.Transport.ClientCredentialType = HttpClientCredentialType.None;
        try
        {
            ServiceHost sh = new ServiceHost(typeof(MyService), uri);
            sh.AddServiceEndpoint(typeof(IService), binding, "");
            ServiceMetadataBehavior smb;
            smb = sh.Description.Behaviors.Find <ServiceMetadataBehavior>();
            if (smb == null)
            {
                smb = new ServiceMetadataBehavior()
                {
                    HttpsGetEnabled = true,
                };
                sh.Description.Behaviors.Add(smb);
            }
            Binding mexbinding = MetadataExchangeBindings.CreateMexHttpsBinding();
            sh.AddServiceEndpoint(typeof(IMetadataExchange), mexbinding, "mex");
            sh.Open();
            WriteLog($"Service is ready at {DateTime.Now.ToString("hh-mm-ss")}");
        }
        catch (Exception e)
        {
            WriteLog(e.ToString());
            throw;
        }
    }
Ejemplo n.º 2
0
        private static MetadataExchangeClient CreateMetadataExchangeClient(EndpointAddress endpointReference)
        {
            string scheme = endpointReference.Uri.Scheme;

            if (string.Compare(scheme, Uri.UriSchemeHttp, StringComparison.OrdinalIgnoreCase) == 0)
            {
                WSHttpBinding mexHttpBinding = (WSHttpBinding)MetadataExchangeBindings.CreateMexHttpBinding();
                mexHttpBinding.MaxReceivedMessageSize = maxReceivedMessageSize;
                return(new MetadataExchangeClient(mexHttpBinding));
            }
            if (string.Compare(scheme, Uri.UriSchemeHttps, StringComparison.OrdinalIgnoreCase) == 0)
            {
                WSHttpBinding mexHttpsBinding = (WSHttpBinding)MetadataExchangeBindings.CreateMexHttpsBinding();
                mexHttpsBinding.MaxReceivedMessageSize = maxReceivedMessageSize;
                return(new MetadataExchangeClient(mexHttpsBinding));
            }
            if (string.Compare(scheme, Uri.UriSchemeNetTcp, StringComparison.OrdinalIgnoreCase) == 0)
            {
                CustomBinding mexTcpBinding = (CustomBinding)MetadataExchangeBindings.CreateMexTcpBinding();
                mexTcpBinding.Elements.Find <TcpTransportBindingElement>().MaxReceivedMessageSize = maxReceivedMessageSize;
                return(new MetadataExchangeClient(mexTcpBinding));
            }
            if (string.Compare(scheme, Uri.UriSchemeNetPipe, StringComparison.OrdinalIgnoreCase) != 0)
            {
                string message = string.Format("Cannot obtain Metadata from {0}. The URI scheme is not supported by default. Add a client endpoint in config with name=\"\" and contract=\"IMetadataExchange\" and an appropriate binding to obtain Metadata from this URI.", endpointReference.Uri.OriginalString);
                throw new ArgumentException(message);
            }
            CustomBinding mexNamedPipeBinding = (CustomBinding)MetadataExchangeBindings.CreateMexNamedPipeBinding();

            mexNamedPipeBinding.Elements.Find <NamedPipeTransportBindingElement>().MaxReceivedMessageSize = maxReceivedMessageSize;
            return(new MetadataExchangeClient(mexNamedPipeBinding));
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Find the wsdl importer
        /// </summary>
        /// <param name="wsdlUri">The wsdl uri</param>
        /// <returns>A wsdl importer</returns>
        private WsdlImporter GetWsdlImporter(Uri wsdlUri)
        {
            _logger.WriteDebug($"GetWsdlImporter wsdlUri[{wsdlUri}]");
            WSHttpBinding mexBinding = null;

            if (wsdlUri.Scheme == Uri.UriSchemeHttp)
            {
                mexBinding = (WSHttpBinding)MetadataExchangeBindings.CreateMexHttpBinding();
            }
            else
            {
                mexBinding = (WSHttpBinding)MetadataExchangeBindings.CreateMexHttpsBinding();
            }
            mexBinding.MaxReceivedMessageSize = Int32.MaxValue;
            mexBinding.MaxBufferPoolSize      = Int32.MaxValue;
            mexBinding.ReaderQuotas.MaxStringContentLength = Int32.MaxValue;
            mexBinding.ReaderQuotas.MaxNameTableCharCount  = Int32.MaxValue;
            mexBinding.ReaderQuotas.MaxArrayLength         = Int32.MaxValue;
            mexBinding.ReaderQuotas.MaxBytesPerRead        = Int32.MaxValue;
            mexBinding.ReaderQuotas.MaxDepth = 64;

            var mexClient = new MetadataExchangeClient(mexBinding);

            mexClient.MaximumResolvedReferences = int.MaxValue;

            var metadataSet = mexClient.GetMetadata(wsdlUri, MetadataExchangeClientMode.HttpGet);

            return(new WsdlImporter(metadataSet));
        }
Ejemplo n.º 4
0
        public ServiceEndpoint HostSecured <T>(ServiceHost host, ServiceInfo serviceInfo)
        {
            const string addressUriFormat = "{0}://{1}:{2}/{3}/{4}";
            string       endpointAddress  = string.Format(addressUriFormat, "https", serviceInfo.ServerName, serviceInfo.Binding.Configuration.Port,
                                                          serviceInfo.Folder,
                                                          serviceInfo.ServiceName);
            var httpBinding = serviceInfo.Binding.WcfBinding as WSHttpBinding;
            var smb         = host.Description.Behaviors.Find <ServiceMetadataBehavior>();

            if (smb == null)
            {
                smb = new ServiceMetadataBehavior();
                smb.MetadataExporter.PolicyVersion = PolicyVersion.Policy15;
                host.Description.Behaviors.Add(smb);
            }

            httpBinding.Security.Mode = SecurityMode.Transport;
            httpBinding.Security.Transport.ClientCredentialType = HttpClientCredentialType.None;

            var mexAddress = new Uri(endpointAddress + "MEX");

            smb.HttpsGetEnabled = true;
            smb.HttpsGetUrl     = mexAddress;

            var serviceEndpoint = host.AddServiceEndpoint(typeof(T), serviceInfo.Binding.WcfBinding, endpointAddress);

            host.AddServiceEndpoint(ServiceMetadataBehavior.MexContractName,
                                    MetadataExchangeBindings.CreateMexHttpsBinding(), mexAddress);

            return(serviceEndpoint);
        }
Ejemplo n.º 5
0
        public override ServiceHostBase CreateServiceHost
            (string service, Uri[] baseAddresses)
        {
            ServiceHost host = new ServiceHost(typeof(IssHosted.ServiceInterfaces.EchoService),
                                               baseAddresses);

            host.AddServiceEndpoint(typeof(IEchoService), new ServiceproviderBinding(true), "");
            host.AddServiceEndpoint(typeof(IEchoService), new ServiceproviderBinding(false), "");

            // Configure our certificate and issuer certificate validation settings on the service credentials
            host.Credentials.ServiceCertificate.SetCertificate(SigningCertificateNameGenevaService, StoreLocation.LocalMachine, StoreName.My);
            // Enable metadata generation via HTTP GET
            ServiceMetadataBehavior smb = new ServiceMetadataBehavior();

            smb.HttpsGetEnabled = true;
            smb.HttpGetEnabled  = true;
            host.Description.Behaviors.Add(smb);

            host.AddServiceEndpoint(typeof(IMetadataExchange), MetadataExchangeBindings.CreateMexHttpsBinding(), "mex");
            host.AddServiceEndpoint(typeof(IMetadataExchange), MetadataExchangeBindings.CreateMexHttpBinding(), "mex");


            // Configure the service host to use the Geneva Framework
            ServiceConfiguration configuration = new ServiceConfiguration();

            configuration.IssuerNameRegistry = new TrustedIssuerNameRegistry();
            configuration.SecurityTokenHandlers.Configuration.AudienceRestriction.AllowedAudienceUris.Add(new Uri("http://localhost/Echo/service.svc/Echo"));
            configuration.SecurityTokenHandlers.Configuration.AudienceRestriction.AllowedAudienceUris.Add(new Uri("http://localhost:6020/Echo"));
            configuration.SecurityTokenHandlers.Configuration.AudienceRestriction.AllowedAudienceUris.Add(new Uri("https://172.30.161.162:8181/poc-provider/ProviderService"));
            configuration.SecurityTokenHandlers.Configuration.AudienceRestriction.AllowedAudienceUris.Add(new Uri("https://172.16.232.1:8181/poc-provider/ProviderService"));
            configuration.SecurityTokenHandlers.Configuration.AudienceRestriction.AllowedAudienceUris.Add(new Uri("http://csky-pc/test/Service1.svc"));
            FederatedServiceCredentials.ConfigureServiceHost(host, configuration);
            return(host);
        }
Ejemplo n.º 6
0
        public void AddAllMexEndpoint()
        {
            Debug.Assert(HasMexEndPoint == false);
            foreach (Uri baseAddress in BaseAddresses)
            {
                System.ServiceModel.Channels.Binding binding = null;
                switch (baseAddress.Scheme)
                {
                case "net.tcp":
                    binding = MetadataExchangeBindings.CreateMexTcpBinding();
                    break;

                case "net.pipe":
                    binding = MetadataExchangeBindings.CreateMexNamedPipeBinding();
                    break;

                case "http":
                    binding = MetadataExchangeBindings.CreateMexHttpBinding();
                    break;

                case "https":
                    binding = MetadataExchangeBindings.CreateMexHttpsBinding();
                    break;
                }
                if (binding != null)
                {
                    AddServiceEndpoint(typeof(IMetadataExchange), binding, "Mex");
                }
            }
        }
Ejemplo n.º 7
0
        public void Run()
        {
            var baseAddress = new Uri("https://localhost:8080/hello");

            _host = new ServiceHost(typeof(UserAdmin), baseAddress);

            var smb = new ServiceMetadataBehavior
            {
                HttpsGetEnabled  = true,
                MetadataExporter = { PolicyVersion = PolicyVersion.Policy15 }
            };

            _host.Description.Behaviors.Add(smb);
            var mexBinding = MetadataExchangeBindings.CreateMexHttpsBinding();

            _host.AddServiceEndpoint(
                ServiceMetadataBehavior.MexContractName,
                mexBinding,
                "mex"
                );
            _host.Credentials.ServiceCertificate.Certificate = new X509Certificate2("c:\\temp\\TempCA.pfx");
            var binding = new BasicHttpBinding
            {
                Security =
                {
                    Mode = BasicHttpSecurityMode.Transport,
                }
            };

            _host.AddServiceEndpoint(typeof(IUserAdmin), binding, "");
            _host.Authorization.ServiceAuthorizationManager = new WcfServiceAuthorizationManager();
            _host.Description.Behaviors.Find <ServiceDebugBehavior>().IncludeExceptionDetailInFaults = true;
            _host.AddDependencyInjectionBehavior <IUserAdmin>(_scope);
            _host.Open();
        }
        public static void AddDefaultMEXEndPoint(this ServiceHost host)
        {
            const string MexExtension = "Mex";

            ServiceMetadataBehavior mexBehavior = new ServiceMetadataBehavior();

            host.Description.Behaviors.Add(mexBehavior);

            foreach (Uri baseAddress in host.BaseAddresses)
            {
                if (baseAddress.Scheme == Uri.UriSchemeHttp)
                {
                    mexBehavior.HttpGetEnabled = true;
                    host.AddServiceEndpoint(ServiceMetadataBehavior.MexContractName,
                                            MetadataExchangeBindings.CreateMexHttpBinding(), MexExtension);
                }
                else if (baseAddress.Scheme == Uri.UriSchemeHttps)
                {
                    mexBehavior.HttpsGetEnabled = true;
                    host.AddServiceEndpoint(ServiceMetadataBehavior.MexContractName,
                                            MetadataExchangeBindings.CreateMexHttpsBinding(), MexExtension);
                }
                else if (baseAddress.Scheme == Uri.UriSchemeNetPipe)
                {
                    host.AddServiceEndpoint(ServiceMetadataBehavior.MexContractName,
                                            MetadataExchangeBindings.CreateMexNamedPipeBinding(), MexExtension);
                }
                else if (baseAddress.Scheme == Uri.UriSchemeNetTcp)
                {
                    host.AddServiceEndpoint(ServiceMetadataBehavior.MexContractName,
                                            MetadataExchangeBindings.CreateMexTcpBinding(), MexExtension);
                }
            }
        }
        public void CreateMexHttpsBinding()
        {
            var b = MetadataExchangeBindings.CreateMexHttpsBinding() as WSHttpBinding;

            Assert.IsNotNull(b, "#1");
            Assert.AreEqual(SecurityMode.Transport, b.Security.Mode, "#2");
            Assert.IsFalse(b.TransactionFlow, "#3");
            Assert.IsFalse(b.ReliableSession.Enabled, "#4");
            Assert.IsFalse(b.CreateBindingElements().Any(be => be is SecurityBindingElement), "#b1");
            Assert.IsTrue(b.CreateBindingElements().Any(be => be is TransactionFlowBindingElement), "#b2");
            Assert.IsFalse(b.CreateBindingElements().Any(be => be is ReliableSessionBindingElement), "#b3");
            Assert.IsTrue(new TransactionFlowBindingElement().TransactionProtocol == TransactionProtocol.Default, "#x1");
            Assert.AreEqual(MessageVersion.Soap12WSAddressing10, b.MessageVersion, "#5");
            Assert.AreEqual(MessageVersion.Soap12WSAddressing10, b.GetProperty <MessageVersion>(new BindingParameterCollection()), "#6");
            Assert.AreEqual(Uri.UriSchemeHttps, b.Scheme, "#8");

            var host = new ServiceHost(typeof(MetadataExchange));

            host.AddServiceEndpoint(typeof(IMetadataExchange), MetadataExchangeBindings.CreateMexHttpsBinding(), CreateUri("https://localhost:30158"));
            host.Open();
            try
            {
                // it still does not rewrite MessageVersion.None. It's rather likely ServiceMetadataExtension which does overwriting.
                Assert.AreEqual(MessageVersion.Soap12WSAddressing10, ((ChannelDispatcher)host.ChannelDispatchers[0]).MessageVersion, "#7");
            }
            finally
            {
                host.Close();
            }
        }
        SecurityMode SetMexAndSecurity(ServiceHost host,
                                       string mexScheme)
        {
            ServiceMetadataBehavior mexHttpBehavior = new ServiceMetadataBehavior();
            Uri          mexUri = new Uri("/mex", UriKind.Relative);
            Binding      binding;
            SecurityMode securityMode;

            if (mexScheme == Uri.UriSchemeHttp)
            {
                mexHttpBehavior.HttpGetEnabled = true;
                binding      = MetadataExchangeBindings.CreateMexHttpBinding();
                securityMode = SecurityMode.Message;
            }
            else
            {
                mexHttpBehavior.HttpsGetEnabled = true;
                binding      = MetadataExchangeBindings.CreateMexHttpsBinding();
                securityMode = SecurityMode.TransportWithMessageCredential;
            }
            host.Description.Behaviors.Add(mexHttpBehavior);
            host.AddServiceEndpoint(typeof(IMetadataExchange), binding, mexUri);

            return(securityMode);
        }
Ejemplo n.º 11
0
        private void addmexbehavior()
        {
            ServiceMetadataBehavior serviceMetadataBehavior = base.Description.Behaviors.Find <ServiceMetadataBehavior>();

            if (serviceMetadataBehavior == null)
            {
                serviceMetadataBehavior = new ServiceMetadataBehavior();
                base.Description.Behaviors.Add(serviceMetadataBehavior);
            }
            foreach (Uri current in base.BaseAddresses)
            {
                if (current.Scheme == Uri.UriSchemeHttp)
                {
                    serviceMetadataBehavior.HttpGetEnabled = true;
                    base.AddServiceEndpoint("IMetadataExchange", MetadataExchangeBindings.CreateMexHttpBinding(), "mex");
                }
                else if (current.Scheme == Uri.UriSchemeHttps)
                {
                    serviceMetadataBehavior.HttpsGetEnabled = true;
                    base.AddServiceEndpoint("IMetadataExchange", MetadataExchangeBindings.CreateMexHttpsBinding(), "mex");
                }
                else if (current.Scheme == Uri.UriSchemeNetPipe)
                {
                    base.AddServiceEndpoint("IMetadataExchange", MetadataExchangeBindings.CreateMexNamedPipeBinding(), "mex");
                }
                else if (current.Scheme == Uri.UriSchemeNetTcp)
                {
                    base.AddServiceEndpoint("IMetadataExchange", MetadataExchangeBindings.CreateMexTcpBinding(), "mex");
                }
            }
        }
        //Overriding ApplyConfiguration() allows us to
        //alter the ServiceDescription prior to opening
        //the service host.
        protected override void ApplyConfiguration()
        {
            //First, we call base.ApplyConfiguration()
            //to read any configuration that was provided for
            //the service we're hosting. After this call,
            //this.ServiceDescription describes the service
            //as it was configured.
            base.ApplyConfiguration();

            //Now that we've populated the ServiceDescription, we can reach into it
            //and do interesting things (in this case, we'll add an instance of
            //ServiceMetadataBehavior if it's not already there.
            ServiceMetadataBehavior mexBehavior = this.Description.Behaviors.Find <ServiceMetadataBehavior>();

            if (mexBehavior == null)
            {
                mexBehavior = new ServiceMetadataBehavior();
                this.Description.Behaviors.Add(mexBehavior);
            }
            else
            {
                //Metadata behavior has already been configured,
                //so we don't have any work to do.
                return;
            }

            //Add a metadata endpoint at each base address
            //using the "/mex" addressing convention
            foreach (Uri baseAddress in this.BaseAddresses)
            {
                if (baseAddress.Scheme == Uri.UriSchemeHttp)
                {
                    mexBehavior.HttpGetEnabled = true;
                    this.AddServiceEndpoint(ServiceMetadataBehavior.MexContractName,
                                            MetadataExchangeBindings.CreateMexHttpBinding(),
                                            "mex");
                }
                else if (baseAddress.Scheme == Uri.UriSchemeHttps)
                {
                    mexBehavior.HttpsGetEnabled = true;
                    this.AddServiceEndpoint(ServiceMetadataBehavior.MexContractName,
                                            MetadataExchangeBindings.CreateMexHttpsBinding(),
                                            "mex");
                }
                else if (baseAddress.Scheme == Uri.UriSchemeNetPipe)
                {
                    this.AddServiceEndpoint(ServiceMetadataBehavior.MexContractName,
                                            MetadataExchangeBindings.CreateMexNamedPipeBinding(),
                                            "mex");
                }
                else if (baseAddress.Scheme == Uri.UriSchemeNetTcp)
                {
                    this.AddServiceEndpoint(ServiceMetadataBehavior.MexContractName,
                                            MetadataExchangeBindings.CreateMexTcpBinding(),
                                            "mex");
                }
            }
        }
Ejemplo n.º 13
0
        private void CreateMetadataBehavior(SpringServiceHost ssh, ServiceMetadataBehavior smb, ServiceEndpointElement metadataEle)
        {
            if (smb == null)
            {
                smb = new ServiceMetadataBehavior();
                if (ssh.BaseAddresses.Any(o => o.Scheme.ToLower() == Uri.UriSchemeHttp))
                {
                    smb.HttpGetEnabled = true;
                }
                ssh.Description.Behaviors.Add(smb);
            }

            foreach (var baseAddress in ssh.BaseAddresses)
            {
                //BindingElement bindingElement = null;
                Binding bindingElement = null;
                switch (baseAddress.Scheme)
                {
                case  "net.tcp":
                {
                    bindingElement = MetadataExchangeBindings.CreateMexTcpBinding();
                    //bindingElement = new TcpTransportBindingElement();
                    break;
                }

                case "net.pipe":
                {
                    bindingElement = MetadataExchangeBindings.CreateMexNamedPipeBinding();
                    //bindingElement = new NamedPipeTransportBindingElement();
                    break;
                }

                case "http":
                {
                    bindingElement = MetadataExchangeBindings.CreateMexHttpBinding();
                    //bindingElement = new HttpTransportBindingElement();
                    break;
                }

                case "https":
                {
                    bindingElement = MetadataExchangeBindings.CreateMexHttpsBinding();
                    //bindingElement = new HttpsTransportBindingElement();
                    break;
                }

                default:
                    throw new ProtocolException("The base address {0} Unable to identify".FormatString(baseAddress.ToString()));
                }
                if (bindingElement != null)
                {
                    //Binding binding = new CustomBinding(bindingElement);
                    ssh.AddServiceEndpoint(typeof(IMetadataExchange), bindingElement, "MEX");
                }
            }
        }
Ejemplo n.º 14
0
        private void AddWellKnownMexEndpoints(ServiceHost serviceHost)
        {
            bool relativeAddress;

            foreach (var baseAddress in GetBaseAddresses(serviceHost, out relativeAddress))
            {
                Binding binding    = null;
                var     mexAddress = address;
                var     scheme     = baseAddress.Scheme;

                if (StringComparer.OrdinalIgnoreCase.Equals(scheme, Uri.UriSchemeHttp))
                {
                    binding = newBinding ? null : FindCompatibleBinding(serviceHost, scheme);
                    if (binding == null)
                    {
                        binding    = MetadataExchangeBindings.CreateMexHttpBinding();
                        mexAddress = relativeAddress ? string.Empty : baseAddress.AbsoluteUri;
                    }
                }
                else if (StringComparer.OrdinalIgnoreCase.Equals(scheme, Uri.UriSchemeHttps))
                {
                    binding = newBinding ? null : FindCompatibleBinding(serviceHost, scheme);
                    if (binding == null)
                    {
                        binding    = MetadataExchangeBindings.CreateMexHttpsBinding();
                        mexAddress = relativeAddress ? string.Empty : baseAddress.AbsoluteUri;
                    }
                }
                else if (StringComparer.OrdinalIgnoreCase.Equals(scheme, Uri.UriSchemeNetTcp))
                {
                    binding = MetadataExchangeBindings.CreateMexTcpBinding();
                    var tcpBinding = new CustomBinding(binding);
                    var transport  = tcpBinding.Elements.OfType <TcpTransportBindingElement>().Single();
                    transport.PortSharingEnabled = true;
                    binding = tcpBinding;
                    if (relativeAddress == false)
                    {
                        mexAddress = string.Format("{0}/{1}", baseAddress.AbsoluteUri, address);
                    }
                }
                else if (StringComparer.OrdinalIgnoreCase.Equals(scheme, Uri.UriSchemeNetPipe))
                {
                    binding = MetadataExchangeBindings.CreateMexNamedPipeBinding();
                    if (relativeAddress == false)
                    {
                        mexAddress = string.Format("{0}/{1}", baseAddress.AbsoluteUri, address);
                    }
                }

                if (binding != null)
                {
                    serviceHost.AddServiceEndpoint(typeof(IMetadataExchange), binding, mexAddress);
                }
            }
        }
Ejemplo n.º 15
0
        /// <summary>
        /// Apply configuration
        /// </summary>
        protected override void ApplyConfiguration()
        {
            this.Description.ConfigurationName = this.ServiceName;
            base.ApplyConfiguration();

            ServiceMetadataBehavior mexBehavior = this.Description.Behaviors.Find <ServiceMetadataBehavior>();

            if (mexBehavior == null)
            {
                mexBehavior = new ServiceMetadataBehavior();
                this.Description.Behaviors.Add(mexBehavior);
            }
            else
            {
                //Metadata behavior has already been configured,
                //so we don't have any work to do.
                return;
            }

            //Add a metadata endpoint at each base address
            //using the "/mex" addressing convention
            foreach (Uri baseAddress in this.BaseAddresses)
            {
                if (baseAddress.Scheme == Uri.UriSchemeHttp)
                {
                    mexBehavior.HttpGetEnabled = true;
                    this.AddServiceEndpoint(ServiceMetadataBehavior.MexContractName,
                                            MetadataExchangeBindings.CreateMexHttpBinding(),
                                            "mex");
                }
                else if (baseAddress.Scheme == Uri.UriSchemeHttps)
                {
                    mexBehavior.HttpsGetEnabled = true;
                    this.AddServiceEndpoint(ServiceMetadataBehavior.MexContractName,
                                            MetadataExchangeBindings.CreateMexHttpsBinding(),
                                            "mex");
                }
                else if (baseAddress.Scheme == Uri.UriSchemeNetPipe)
                {
                    this.AddServiceEndpoint(ServiceMetadataBehavior.MexContractName,
                                            MetadataExchangeBindings.CreateMexNamedPipeBinding(),
                                            "mex");
                }
                else if (baseAddress.Scheme == Uri.UriSchemeNetTcp)
                {
                    this.AddServiceEndpoint(ServiceMetadataBehavior.MexContractName,
                                            MetadataExchangeBindings.CreateMexTcpBinding(),
                                            "mex");
                }
            }
        }
Ejemplo n.º 16
0
        /// <summary>
        /// Configures metadata (WSDL) for the service host. The method loops through the
        /// base addresses, and adds mex endpoints for http, https, net.tcp and net.pipe
        /// addresses, only when no mex endpoints have been previously added by the user.
        /// For http and htps addresses, HTTP and HTTPS "Get" mechanism for WSDL retrieval
        /// is enabled.
        /// </summary>
        protected virtual void ConfigureMetadata()
        {
            if (this.BaseAddresses == null || this.BaseAddresses.Count == 0)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperInvalidOperation(SR.GetString(SR.ID3140));
            }

            // Check if a ServiceMetadataBehavior is added.
            ServiceMetadataBehavior metadataBehavior = Description.Behaviors.Find <ServiceMetadataBehavior>();

            if (metadataBehavior == null)
            {
                metadataBehavior = new ServiceMetadataBehavior();
                Description.Behaviors.Add(metadataBehavior);
            }

            // Check if an Mex endpoint has alread been added by user. This can be enabled through
            // configuration.
            bool isMexEndpointAlreadyAdded = (Description.Endpoints.Find(typeof(IMetadataExchange)) != null);

            Binding mexBinding = null;

            foreach (Uri baseAddress in this.BaseAddresses)
            {
                if (StringComparer.OrdinalIgnoreCase.Equals(baseAddress.Scheme, Uri.UriSchemeHttp))
                {
                    metadataBehavior.HttpGetEnabled = true;
                    mexBinding = MetadataExchangeBindings.CreateMexHttpBinding();
                }
                else if (StringComparer.OrdinalIgnoreCase.Equals(baseAddress.Scheme, Uri.UriSchemeHttps))
                {
                    metadataBehavior.HttpsGetEnabled = true;
                    mexBinding = MetadataExchangeBindings.CreateMexHttpsBinding();
                }
                else if (StringComparer.OrdinalIgnoreCase.Equals(baseAddress.Scheme, Uri.UriSchemeNetTcp))
                {
                    mexBinding = MetadataExchangeBindings.CreateMexTcpBinding();
                }
                else if (StringComparer.OrdinalIgnoreCase.Equals(baseAddress.Scheme, Uri.UriSchemeNetPipe))
                {
                    mexBinding = MetadataExchangeBindings.CreateMexNamedPipeBinding();
                }

                if (!isMexEndpointAlreadyAdded && (mexBinding != null))
                {
                    AddServiceEndpoint(ServiceMetadataBehavior.MexContractName, mexBinding, "mex");
                }

                mexBinding = null;
            }
        }
Ejemplo n.º 17
0
        /// <summary>
        /// Adds the mex endpoints.
        /// </summary>
        /// <param name="host">The service host.</param>
        public static void AddMexEndpoints(this ServiceHostBase host)
        {
            Type T           = host.GetType();
            var  logger      = LogManager.GetLogger(T.Name);
            var  mexBehavior = host.Description.Behaviors.Find <ServiceMetadataBehavior>();

            if (mexBehavior == null)
            {
                mexBehavior = new ServiceMetadataBehavior();
                host.Description.Behaviors.Add(mexBehavior);
            }
            logger.Debug("Checking possible MEX endpoints...");
            foreach (Uri baseAddress in host.BaseAddresses)
            {
                logger.Debug("\tAdding endpoint {0}", baseAddress.AbsoluteUri);
                if (baseAddress.Scheme == Uri.UriSchemeNetPipe)
                {
                    host.AddServiceEndpoint(ServiceMetadataBehavior.MexContractName,
                                            MetadataExchangeBindings.CreateMexNamedPipeBinding(),
                                            "mex");
                }
                if (baseAddress.Scheme == Uri.UriSchemeHttps)
                {
                    if (ConfigurationHelper.SecureMex)
                    {
                        mexBehavior.HttpsGetEnabled = true;
                        mexBehavior.HttpsGetUrl     = baseAddress;
                        host.AddServiceEndpoint(ServiceMetadataBehavior.MexContractName,
                                                MetadataExchangeBindings.CreateMexHttpsBinding(),
                                                "mex");
                    }
                }
                if (baseAddress.Scheme == Uri.UriSchemeHttp)
                {
                    if (!ConfigurationHelper.SecureMex)
                    {
                        mexBehavior.HttpGetEnabled = true;
                        mexBehavior.HttpGetUrl     = baseAddress;
                        host.AddServiceEndpoint(ServiceMetadataBehavior.MexContractName,
                                                MetadataExchangeBindings.CreateMexHttpBinding(),
                                                "mex");
                    }
                }
                if (baseAddress.Scheme == Uri.UriSchemeNetTcp)
                {
                    host.AddServiceEndpoint(ServiceMetadataBehavior.MexContractName,
                                            MetadataExchangeBindings.CreateMexTcpBinding(),
                                            "mex");
                }
            }
        }
Ejemplo n.º 18
0
        public static MetadataSet GetMetadataSet(string url)
        {
            MetadataExchangeClientMode mode = MetadataExchangeClientMode.MetadataExchange;
            int maxReceivedMessageSize      = 3000000;
            Uri address = new Uri(url);

            System.ServiceModel.Channels.Binding mexBinding = null;
            if (string.Compare(address.Scheme, "http", StringComparison.OrdinalIgnoreCase) == 0)
            {
                mexBinding = MetadataExchangeBindings.CreateMexHttpBinding();
            }
            else if (string.Compare(address.Scheme, "https", StringComparison.OrdinalIgnoreCase) == 0)
            {
                mexBinding = MetadataExchangeBindings.CreateMexHttpsBinding();
            }
            else if (string.Compare(address.Scheme, "net.tcp", StringComparison.OrdinalIgnoreCase) == 0)
            {
                mexBinding = MetadataExchangeBindings.CreateMexTcpBinding();
            }
            else if (string.Compare(address.Scheme, "net.pipe", StringComparison.OrdinalIgnoreCase) == 0)
            {
                mexBinding = MetadataExchangeBindings.CreateMexNamedPipeBinding();
            }
            else
            {
                throw new Exception(string.Format("Not supported schema '{0}' for metadata exchange"));
            }

            if (mexBinding is WSHttpBinding)
            {
                (mexBinding as WSHttpBinding).MaxReceivedMessageSize = maxReceivedMessageSize;
                mode = MetadataExchangeClientMode.HttpGet;
            }
            else if (mexBinding is CustomBinding)
            {
                (mexBinding as CustomBinding).Elements.Find <TransportBindingElement>().MaxReceivedMessageSize = maxReceivedMessageSize;
            }
            else
            {
                throw new Exception(string.Format("Not supported binding for metadata exchange"));
            }

            MetadataExchangeClient proxy = new MetadataExchangeClient(mexBinding);

            proxy.ResolveMetadataReferences = true;
            MetadataSet mds = proxy.GetMetadata(address, mode);

            return(mds);
        }
Ejemplo n.º 19
0
        static void Main(string[] args)
        {
            using (ServiceHost host = new ServiceHost(typeof(Service)))
            {
                ServiceMetadataBehavior smb = new ServiceMetadataBehavior();
                smb.HttpsGetEnabled = true;
                host.Description.Behaviors.Add(smb);

                host.AddServiceEndpoint(typeof(IMetadataExchange),
                                        MetadataExchangeBindings.CreateMexHttpsBinding(),
                                        "/mex");

                host.Open();
                PrintServiceDescription(host);
                Console.ReadKey();
            }
        }
    static void Main(string[] args)
    {
        Uri uri = new Uri("https://localhost:11011");
        BasicHttpBinding binding = new BasicHttpBinding();

        binding.Security.Mode = BasicHttpSecurityMode.TransportWithMessageCredential;
        binding.Security.Message.ClientCredentialType   = BasicHttpMessageCredentialType.UserName;
        binding.Security.Transport.ClientCredentialType = HttpClientCredentialType.None;

        using (ServiceHost sh = new ServiceHost(typeof(MyService), uri))
        {
            sh.AddServiceEndpoint(typeof(IService), binding, "");
            ServiceMetadataBehavior smb;
            smb = sh.Description.Behaviors.Find <ServiceMetadataBehavior>();
            if (smb == null)
            {
                smb = new ServiceMetadataBehavior()
                {
                    HttpsGetEnabled = true
                };
                sh.Description.Behaviors.Add(smb);
            }

            sh.Credentials.UserNameAuthentication.UserNamePasswordValidationMode  = System.ServiceModel.Security.UserNamePasswordValidationMode.Custom;
            sh.Credentials.UserNameAuthentication.CustomUserNamePasswordValidator = new CustUserNamePasswordVal();
            Binding mexbinding = MetadataExchangeBindings.CreateMexHttpsBinding();
            sh.AddServiceEndpoint(typeof(IMetadataExchange), mexbinding, "mex");

            sh.Opened += delegate
            {
                Console.WriteLine("Service is ready");
            };
            sh.Closed += delegate
            {
                Console.WriteLine("Service is clsoed");
            };


            sh.Open();

            Console.ReadLine();
            sh.Close();
            Console.ReadLine();
        }
    }
Ejemplo n.º 21
0
        protected override void ApplyConfiguration()
        {
            base.ApplyConfiguration();

            ServiceMetadataBehavior mexBehavior = this.Description.Behaviors.Find <ServiceMetadataBehavior>();

            if (mexBehavior != null)
            {
                return;
            }

            mexBehavior = new ServiceMetadataBehavior();
            this.Description.Behaviors.Add(mexBehavior);

            foreach (Uri baseAddress in this.BaseAddresses)
            {
                if (baseAddress.Scheme == Uri.UriSchemeHttp)
                {
                    mexBehavior.HttpGetEnabled = true;
                    this.AddServiceEndpoint(ServiceMetadataBehavior.MexContractName,
                                            MetadataExchangeBindings.CreateMexHttpBinding(),
                                            "mex");
                }
                else if (baseAddress.Scheme == Uri.UriSchemeHttps)
                {
                    mexBehavior.HttpsGetEnabled = true;
                    this.AddServiceEndpoint(ServiceMetadataBehavior.MexContractName,
                                            MetadataExchangeBindings.CreateMexHttpsBinding(),
                                            "mex");
                }
                else if (baseAddress.Scheme == Uri.UriSchemeNetPipe)
                {
                    this.AddServiceEndpoint(ServiceMetadataBehavior.MexContractName,
                                            MetadataExchangeBindings.CreateMexNamedPipeBinding(),
                                            "mex");
                }
                else if (baseAddress.Scheme == Uri.UriSchemeNetTcp)
                {
                    this.AddServiceEndpoint(ServiceMetadataBehavior.MexContractName,
                                            MetadataExchangeBindings.CreateMexTcpBinding(),
                                            "mex");
                }
            }
        }
Ejemplo n.º 22
0
        private static ServiceHost StartSTS(Type type, string stsLabel, Uri baseAddress, Uri baseMexAddress)
        {
            // Create the service host
            Uri         stsAddress  = new Uri(baseAddress.AbsoluteUri + "/" + stsLabel);
            ServiceHost serviceHost = new ServiceHost(type, stsAddress);

            // Don't require derived keys for the issue method
            ServiceEndpoint            stsEndpoint     = serviceHost.Description.Endpoints.Find(typeof(nl.telin.authep.sts.IWSTrustContract));
            BindingElementCollection   bindingElements = stsEndpoint.Binding.CreateBindingElements();
            SecurityBindingElement     sbe             = bindingElements.Find <SecurityBindingElement>();
            RsaSecurityTokenParameters rsaParams       = new RsaSecurityTokenParameters();

            rsaParams.InclusionMode      = SecurityTokenInclusionMode.Never;
            rsaParams.RequireDerivedKeys = false;
            SupportingTokenParameters requirements = new SupportingTokenParameters();

            requirements.Endorsing.Add(rsaParams);
            sbe.OptionalOperationSupportingTokenParameters.Add(nl.telin.authep.sts.Constants.WSTrust.Actions.Issue, requirements);
            stsEndpoint.Binding = new CustomBinding(bindingElements);
            serviceHost.Credentials.ServiceCertificate.Certificate = SigningCertificate;

            // Add an https mex listener
            string mexAddress = baseMexAddress.AbsoluteUri + "/" + stsLabel + "/mex";

            serviceHost.AddServiceEndpoint(ServiceMetadataBehavior.MexContractName, MetadataExchangeBindings.CreateMexHttpsBinding(), mexAddress);

            // Disable CRL
            serviceHost.Credentials.IssuedTokenAuthentication.RevocationMode = X509RevocationMode.NoCheck;

            // Open the service
            serviceHost.Open();

            // Display the endpoints
            foreach (ChannelDispatcher cd in serviceHost.ChannelDispatchers)
            {
                foreach (EndpointDispatcher ed in cd.Endpoints)
                {
                    Console.WriteLine("Listener = {0}, State = {1}", ed.EndpointAddress.ToString(), cd.State.ToString());
                }
            }

            return(serviceHost);
        }
Ejemplo n.º 23
0
        private static MetadataExchangeResolver CreateMetadataExchangeClient(EndpointAddress endpointAddress)
        {
            MetadataExchangeResolver metadataExchangeClient = null;

            string scheme = endpointAddress.Uri.Scheme;

            if (String.Compare(scheme, MetadataConstants.Uri.UriSchemeHttp, StringComparison.OrdinalIgnoreCase) == 0)
            {
                WSHttpBinding binding = (WSHttpBinding)MetadataExchangeBindings.CreateMexHttpBinding();
                binding.MaxReceivedMessageSize             = MaxRecievedMexMessageSize;
                binding.ReaderQuotas.MaxNameTableCharCount = MaxNameTableCharCount;
                binding.ReaderQuotas.MaxDepth        = MaxDepth;
                binding.ReaderQuotas.MaxBytesPerRead = MaxBytesPerRead;
                metadataExchangeClient = new MetadataExchangeResolver(binding);
            }
            else if (String.Compare(scheme, MetadataConstants.Uri.UriSchemeHttps, StringComparison.OrdinalIgnoreCase) == 0)
            {
                WSHttpBinding binding = (WSHttpBinding)MetadataExchangeBindings.CreateMexHttpsBinding();
                binding.MaxReceivedMessageSize             = MaxRecievedMexMessageSize;
                binding.ReaderQuotas.MaxNameTableCharCount = MaxNameTableCharCount;
                binding.ReaderQuotas.MaxDepth        = MaxDepth;
                binding.ReaderQuotas.MaxBytesPerRead = MaxBytesPerRead;
                metadataExchangeClient = new MetadataExchangeResolver(binding);
            }
            else if (String.Compare(scheme, MetadataConstants.Uri.UriSchemeNetTcp, StringComparison.OrdinalIgnoreCase) == 0)
            {
                CustomBinding binding = (CustomBinding)MetadataExchangeBindings.CreateMexTcpBinding();
                binding.Elements.Find <TcpTransportBindingElement>().MaxReceivedMessageSize = MaxRecievedMexMessageSize;
                metadataExchangeClient = new MetadataExchangeResolver(binding);
            }
            else if (String.Compare(scheme, MetadataConstants.Uri.UriSchemeNetPipe, StringComparison.OrdinalIgnoreCase) == 0)
            {
                CustomBinding binding = (CustomBinding)MetadataExchangeBindings.CreateMexNamedPipeBinding();
                binding.Elements.Find <NamedPipeTransportBindingElement>().MaxReceivedMessageSize = MaxRecievedMexMessageSize;
                metadataExchangeClient = new MetadataExchangeResolver(binding);
            }
            else
            {
                throw new MetadataExchangeException(MetadataResources.ErrCannotCreateAMetadataExchangeClientFormat, endpointAddress.Uri.OriginalString, scheme);
            }

            return(metadataExchangeClient);
        }
    static void Main(string[] args)
    {
        Uri uri = new Uri("https://localhost:21011");
        MtomMessageEncodingBindingElement encoding = new MtomMessageEncodingBindingElement();
        var transport = new HttpsTransportBindingElement();

        transport.TransferMode = TransferMode.Streamed;
        var binding = new CustomBinding(encoding, transport);

        using (ServiceHost sh = new ServiceHost(typeof(MyService), uri))
        {
            sh.AddServiceEndpoint(typeof(IService), binding, "");
            ServiceMetadataBehavior smb;
            smb = sh.Description.Behaviors.Find <ServiceMetadataBehavior>();
            if (smb == null)
            {
                smb = new ServiceMetadataBehavior()
                {
                    HttpsGetEnabled = true
                };
                sh.Description.Behaviors.Add(smb);
            }
            Binding mexbinding = MetadataExchangeBindings.CreateMexHttpsBinding();
            sh.AddServiceEndpoint(typeof(IMetadataExchange), mexbinding, "mex");


            sh.Opened += delegate
            {
                Console.WriteLine("Service is ready");
            };
            sh.Closed += delegate
            {
                Console.WriteLine("Service is clsoed");
            };
            sh.Open();
            Console.ReadLine();
            //pause
            sh.Close();
            Console.ReadLine();
        }
    }
Ejemplo n.º 25
0
        private static MetadataExchangeClient CreateMetadataExchangeClient(Uri serviceUri)
        {
            string scheme = serviceUri.Scheme;
            MetadataExchangeClient result = null;

            if (string.Compare(scheme, Uri.UriSchemeHttp, StringComparison.OrdinalIgnoreCase) == 0)
            {
                WSHttpBinding wSHttpBinding = (WSHttpBinding)MetadataExchangeBindings.CreateMexHttpBinding();
                wSHttpBinding.MaxReceivedMessageSize             = 67108864L;
                wSHttpBinding.ReaderQuotas.MaxNameTableCharCount = 1048576;
                result = new MetadataExchangeClient(wSHttpBinding);
            }
            else
            {
                if (string.Compare(scheme, Uri.UriSchemeHttps, StringComparison.OrdinalIgnoreCase) == 0)
                {
                    WSHttpBinding wSHttpBinding2 = (WSHttpBinding)MetadataExchangeBindings.CreateMexHttpsBinding();
                    wSHttpBinding2.MaxReceivedMessageSize             = 67108864L;
                    wSHttpBinding2.ReaderQuotas.MaxNameTableCharCount = 1048576;
                    result = new MetadataExchangeClient(wSHttpBinding2);
                }
                else
                {
                    if (string.Compare(scheme, Uri.UriSchemeNetTcp, StringComparison.OrdinalIgnoreCase) == 0)
                    {
                        CustomBinding tcpBinding = (CustomBinding)MetadataExchangeBindings.CreateMexTcpBinding();
                        tcpBinding.Elements.Find <TcpTransportBindingElement>().MaxReceivedMessageSize = 67108864L;
                        result = new MetadataExchangeClient(tcpBinding);
                    }
                    else if (string.Compare(scheme, Uri.UriSchemeNetPipe, StringComparison.OrdinalIgnoreCase) != 0)
                    {
                        CustomBinding namedPipeBinding = (CustomBinding)MetadataExchangeBindings.CreateMexNamedPipeBinding();
                        namedPipeBinding.Elements.Find <NamedPipeTransportBindingElement>().MaxReceivedMessageSize = 67108864L;
                        result = new MetadataExchangeClient(namedPipeBinding);
                    }
                }
            }
            return(result);
        }
Ejemplo n.º 26
0
        private static void RegisterLocalHttpsService(string serviceName, int port, Type serviceType, Type contractType)
        {
            Console.WriteLine($"Registering {serviceName} service on port {port}");
            Console.WriteLine($"netsh http add urlacl url=https://localhost:{port}/{serviceName} user=EVERYONE");
            // To be added to package and deploy script;
            // netsh http add urlacl url={ServiceUri} user=EVERYONE
            var strAdrHttp = $"https://localhost:{port}/{serviceName}";

            Uri[] adrbase     = { new Uri(strAdrHttp) };
            var   serviceHost = new ServiceHost(serviceType, adrbase);

            var mBehave = new ServiceMetadataBehavior();

            serviceHost.Description.Behaviors.Add(mBehave);

            var httpb = new BasicHttpBinding();

            httpb.Security.Mode = BasicHttpSecurityMode.Transport;

            serviceHost.AddServiceEndpoint(contractType, httpb, strAdrHttp);
            serviceHost.AddServiceEndpoint(typeof(IMetadataExchange), MetadataExchangeBindings.CreateMexHttpsBinding(), "mex");
            _serviceHosts.Add(serviceHost);
        }
    /// <summary>
    /// https webhttpbinding.
    /// </summary>
    /// <param name="args"></param>
    static void Main(string[] args)
    {
        Uri            uri     = new Uri("https://localhost:4386");
        WebHttpBinding binding = new WebHttpBinding();

        binding.Security.Mode = WebHttpSecurityMode.Transport;
        binding.Security.Transport.ClientCredentialType = HttpClientCredentialType.Basic;


        using (WebServiceHost sh = new WebServiceHost(typeof(TestService), uri))
        {
            sh.AddServiceEndpoint(typeof(ITestService), binding, "");
            ServiceMetadataBehavior smb;
            smb = sh.Description.Behaviors.Find <ServiceMetadataBehavior>();
            if (smb == null)
            {
                smb = new ServiceMetadataBehavior()
                {
                    //HttpsGetEnabled = true
                };
                sh.Description.Behaviors.Add(smb);
            }
            Binding mexbinding = MetadataExchangeBindings.CreateMexHttpsBinding();
            sh.AddServiceEndpoint(typeof(IMetadataExchange), mexbinding, "mex");
            sh.Opened += delegate
            {
                Console.WriteLine("service is ready");
            };
            sh.Closed += delegate
            {
                Console.WriteLine("service is closed");
            };
            sh.Open();
            Console.ReadLine();
            sh.Close();
        }
    }
Ejemplo n.º 28
0
 private static System.ServiceModel.Channels.Binding CreateMexBindingForScheme(string scheme)
 {
     if (scheme == null)
     {
         throw new ArgumentNullException("scheme");
     }
     if (string.Compare(scheme, "http", StringComparison.OrdinalIgnoreCase) == 0)
     {
         return(MetadataExchangeBindings.CreateMexHttpBinding());
     }
     if (string.Compare(scheme, "https", StringComparison.OrdinalIgnoreCase) == 0)
     {
         return(MetadataExchangeBindings.CreateMexHttpsBinding());
     }
     if (string.Compare(scheme, "net.pipe", StringComparison.OrdinalIgnoreCase) == 0)
     {
         return(MetadataExchangeBindings.CreateMexNamedPipeBinding());
     }
     if (string.Compare(scheme, "net.tcp", StringComparison.OrdinalIgnoreCase) == 0)
     {
         return(MetadataExchangeBindings.CreateMexTcpBinding());
     }
     throw new ArgumentException(string.Format("MEX for scheme {0} is not supported.", scheme));
 }
Ejemplo n.º 29
0
        /// <summary>
        /// Static Method GetBinding.
        /// </summary>
        /// <param name="address">Binding address.</param>
        /// <param name="isMexBinding">Whether the binding is mex.</param>
        /// <returns>Instance of Binding.</returns>
        internal static Binding GetBinding(string address, bool isMexBinding)
        {
            if (isMexBinding)
            {
                if (address.StartsWith("mexNamedPipeBinding"))
                {
                    return(MetadataExchangeBindings.CreateMexNamedPipeBinding());
                }

                if (address.StartsWith("mexTcpBinding"))
                {
                    return(MetadataExchangeBindings.CreateMexTcpBinding());
                }

                if (address.StartsWith("mexHttpBinding"))
                {
                    return(MetadataExchangeBindings.CreateMexHttpBinding());
                }

                if (address.StartsWith("mexHttpsBinding"))
                {
                    return(MetadataExchangeBindings.CreateMexHttpsBinding());
                }
            }
            else
            {
                if (address.StartsWith("netNamedPipeBinding"))
                {
                    return(new NetNamedPipeBinding());
                }

                if (address.StartsWith("netTcpBinding"))
                {
                    return(new NetTcpBinding());
                }

                if (address.StartsWith("customBinding"))
                {
                    return(new CustomBinding());
                }

                if (address.StartsWith("basicHttpBinding"))
                {
                    return(new BasicHttpBinding());
                }

                if (address.StartsWith("wsHttpBinding"))
                {
                    return(new WSHttpBinding());
                }

                if (address.StartsWith("ws2007HttpBinding"))
                {
                    return(new WS2007HttpBinding());
                }

                if (address.StartsWith("ws2007FederationHttpBinding"))
                {
                    return(new WS2007FederationHttpBinding());
                }

                if (address.StartsWith("wsDualHttpBinding"))
                {
                    return(new WSDualHttpBinding());
                }

                if (address.StartsWith("wsFederationHttpBinding"))
                {
                    return(new WSFederationHttpBinding());
                }
            }

            return(null);
        }
Ejemplo n.º 30
0
        /// <summary>
        /// Gets the Binding instance according to a Binding type name.
        /// </summary>
        /// <param name="bindingTypeName">The name of <see cref="T:System.ServiceModel.Channels.Binding" /> for the service.</param>
        /// <returns>Instance of Binding.</returns>
        public static Binding GetBinding(string bindingTypeName)
        {
            if (bindingTypeName.Equals("BasicHttpBinding", StringComparison.OrdinalIgnoreCase))
            {
                return(new BasicHttpBinding()
                {
                    OpenTimeout = TimeSpan.FromMinutes(10), CloseTimeout = TimeSpan.FromMinutes(10), SendTimeout = TimeSpan.FromMinutes(10), ReceiveTimeout = TimeSpan.FromMinutes(10), MaxBufferPoolSize = int.MaxValue, MaxBufferSize = int.MaxValue, MaxReceivedMessageSize = int.MaxValue, ReaderQuotas = XmlDictionaryReaderQuotas.Max
                });
            }

            if (bindingTypeName.Equals("WSHttpBinding", StringComparison.OrdinalIgnoreCase))
            {
                return(new WSHttpBinding()
                {
                    OpenTimeout = TimeSpan.FromMinutes(10), CloseTimeout = TimeSpan.FromMinutes(10), SendTimeout = TimeSpan.FromMinutes(10), ReceiveTimeout = TimeSpan.FromMinutes(10), MaxBufferPoolSize = int.MaxValue, MaxReceivedMessageSize = int.MaxValue, ReaderQuotas = XmlDictionaryReaderQuotas.Max
                });
            }

            if (bindingTypeName.Equals("NetTcpBinding", StringComparison.OrdinalIgnoreCase))
            {
                return(new NetTcpBinding()
                {
                    OpenTimeout = TimeSpan.FromMinutes(10), CloseTimeout = TimeSpan.FromMinutes(10), SendTimeout = TimeSpan.FromMinutes(10), ReceiveTimeout = TimeSpan.FromMinutes(10), MaxBufferPoolSize = int.MaxValue, MaxBufferSize = int.MaxValue, MaxReceivedMessageSize = int.MaxValue, ListenBacklog = int.MaxValue, MaxConnections = ushort.MaxValue, PortSharingEnabled = true, ReaderQuotas = XmlDictionaryReaderQuotas.Max
                });
            }

            if (bindingTypeName.Equals("NetNamedPipeBinding", StringComparison.OrdinalIgnoreCase))
            {
                return(new NetNamedPipeBinding()
                {
                    OpenTimeout = TimeSpan.FromMinutes(10), CloseTimeout = TimeSpan.FromMinutes(10), SendTimeout = TimeSpan.FromMinutes(10), ReceiveTimeout = TimeSpan.FromMinutes(10), MaxBufferPoolSize = int.MaxValue, MaxBufferSize = int.MaxValue, MaxReceivedMessageSize = int.MaxValue, MaxConnections = int.MaxValue, ReaderQuotas = XmlDictionaryReaderQuotas.Max
                });
            }

            if (bindingTypeName.Equals("WS2007HttpBinding", StringComparison.OrdinalIgnoreCase))
            {
                return(new WS2007HttpBinding()
                {
                    OpenTimeout = TimeSpan.FromMinutes(10), CloseTimeout = TimeSpan.FromMinutes(10), SendTimeout = TimeSpan.FromMinutes(10), ReceiveTimeout = TimeSpan.FromMinutes(10), MaxBufferPoolSize = int.MaxValue, MaxReceivedMessageSize = int.MaxValue, ReaderQuotas = XmlDictionaryReaderQuotas.Max
                });
            }

            if (bindingTypeName.Equals("WS2007FederationHttpBinding", StringComparison.OrdinalIgnoreCase))
            {
                return(new WS2007FederationHttpBinding()
                {
                    OpenTimeout = TimeSpan.FromMinutes(10), CloseTimeout = TimeSpan.FromMinutes(10), SendTimeout = TimeSpan.FromMinutes(10), ReceiveTimeout = TimeSpan.FromMinutes(10), MaxBufferPoolSize = int.MaxValue, MaxReceivedMessageSize = int.MaxValue, ReaderQuotas = XmlDictionaryReaderQuotas.Max
                });
            }

            if (bindingTypeName.Equals("WSDualHttpBinding", StringComparison.OrdinalIgnoreCase))
            {
                return(new WSDualHttpBinding()
                {
                    OpenTimeout = TimeSpan.FromMinutes(10), CloseTimeout = TimeSpan.FromMinutes(10), SendTimeout = TimeSpan.FromMinutes(10), ReceiveTimeout = TimeSpan.FromMinutes(10), MaxBufferPoolSize = int.MaxValue, MaxReceivedMessageSize = int.MaxValue, ReaderQuotas = XmlDictionaryReaderQuotas.Max
                });
            }

            if (bindingTypeName.Equals("WSFederationHttpBinding", StringComparison.OrdinalIgnoreCase))
            {
                return(new WSFederationHttpBinding()
                {
                    OpenTimeout = TimeSpan.FromMinutes(10), CloseTimeout = TimeSpan.FromMinutes(10), SendTimeout = TimeSpan.FromMinutes(10), ReceiveTimeout = TimeSpan.FromMinutes(10), MaxBufferPoolSize = int.MaxValue, MaxReceivedMessageSize = int.MaxValue, ReaderQuotas = XmlDictionaryReaderQuotas.Max
                });
            }

            if (bindingTypeName.Equals("NetMsmqBinding", StringComparison.OrdinalIgnoreCase))
            {
                return(new NetMsmqBinding()
                {
                    OpenTimeout = TimeSpan.FromMinutes(10), CloseTimeout = TimeSpan.FromMinutes(10), SendTimeout = TimeSpan.FromMinutes(10), ReceiveTimeout = TimeSpan.FromMinutes(10), MaxBufferPoolSize = int.MaxValue, MaxReceivedMessageSize = int.MaxValue, ReaderQuotas = XmlDictionaryReaderQuotas.Max
                });
            }

            if (bindingTypeName.Equals("NetPeerTcpBinding", StringComparison.OrdinalIgnoreCase))
            {
                return(new NetPeerTcpBinding()
                {
                    OpenTimeout = TimeSpan.FromMinutes(10), CloseTimeout = TimeSpan.FromMinutes(10), SendTimeout = TimeSpan.FromMinutes(10), ReceiveTimeout = TimeSpan.FromMinutes(10), MaxBufferPoolSize = int.MaxValue, MaxReceivedMessageSize = int.MaxValue, ReaderQuotas = XmlDictionaryReaderQuotas.Max
                });
            }

            if (bindingTypeName.Equals("CustomBinding", StringComparison.OrdinalIgnoreCase))
            {
                return(new CustomBinding()
                {
                    OpenTimeout = TimeSpan.FromMinutes(10), CloseTimeout = TimeSpan.FromMinutes(10), SendTimeout = TimeSpan.FromMinutes(10), ReceiveTimeout = TimeSpan.FromMinutes(10)
                });
            }

            if (bindingTypeName.Equals("MetadataExchangeBindings", StringComparison.OrdinalIgnoreCase))
            {
                return(MetadataExchangeBindings.CreateMexNamedPipeBinding());
            }

            if (bindingTypeName.Equals("MetadataExchangeBindings", StringComparison.OrdinalIgnoreCase))
            {
                return(MetadataExchangeBindings.CreateMexTcpBinding());
            }

            if (bindingTypeName.Equals("MetadataExchangeBindings", StringComparison.OrdinalIgnoreCase))
            {
                return(MetadataExchangeBindings.CreateMexHttpBinding());
            }

            if (bindingTypeName.Equals("MetadataExchangeBindings", StringComparison.OrdinalIgnoreCase))
            {
                return(MetadataExchangeBindings.CreateMexHttpsBinding());
            }

            return(null);
        }