public static List <WSHttpBinding> GetWsHttpBindings(string exeConfigPath) { if (string.IsNullOrWhiteSpace(exeConfigPath)) { return(null); } var svcSection = Read.Config.ExeConfig.GetServiceModelSection(exeConfigPath); var configs = new List <WSHttpBinding>(); foreach ( var section in svcSection.Bindings.WSHttpBinding.ConfiguredBindings .Cast <WSHttpBindingElement>()) { var df = new WSHttpBinding(); var binding = new WSHttpBinding { Name = section.Name, MaxBufferPoolSize = section.MaxBufferPoolSize > 0 ? section.MaxBufferPoolSize : df.MaxBufferPoolSize, MaxReceivedMessageSize = section.MaxReceivedMessageSize > 0 ? section.MaxReceivedMessageSize : df.MaxReceivedMessageSize, CloseTimeout = section.CloseTimeout != TimeSpan.Zero ? section.CloseTimeout : df.CloseTimeout, OpenTimeout = section.OpenTimeout != TimeSpan.Zero ? section.OpenTimeout : df.OpenTimeout, SendTimeout = section.SendTimeout != TimeSpan.Zero ? section.SendTimeout : df.SendTimeout, ReceiveTimeout = section.ReceiveTimeout != TimeSpan.Zero ? section.ReceiveTimeout : df.ReceiveTimeout, TextEncoding = section.TextEncoding ?? df.TextEncoding, MessageEncoding = section.MessageEncoding, AllowCookies = section.AllowCookies, BypassProxyOnLocal = section.BypassProxyOnLocal, TransactionFlow = section.TransactionFlow, HostNameComparisonMode = section.HostNameComparisonMode, UseDefaultWebProxy = section.UseDefaultWebProxy, }; var readerQuotasSection = section.ReaderQuotas; var readerQuotas = new System.Xml.XmlDictionaryReaderQuotas(); if (readerQuotasSection != null && readerQuotasSection.MaxDepth > 0) { readerQuotas.MaxDepth = readerQuotasSection.MaxDepth; readerQuotas.MaxStringContentLength = readerQuotasSection.MaxStringContentLength; readerQuotas.MaxArrayLength = readerQuotasSection.MaxArrayLength; readerQuotas.MaxBytesPerRead = readerQuotasSection.MaxBytesPerRead; readerQuotas.MaxNameTableCharCount = readerQuotasSection.MaxNameTableCharCount; } else { readerQuotas = null; } var reliableSessionSection = section.ReliableSession; var dfRss = new OptionalReliableSession(); var reliableSession = new OptionalReliableSession { Enabled = reliableSessionSection.Enabled, Ordered = reliableSessionSection.Ordered, InactivityTimeout = reliableSessionSection.InactivityTimeout != TimeSpan.Zero ? reliableSessionSection.InactivityTimeout : dfRss.InactivityTimeout, }; var messageSection = section.Security.Message; var message = new NonDualMessageSecurityOverHttp { EstablishSecurityContext = messageSection.EstablishSecurityContext, ClientCredentialType = messageSection.ClientCredentialType, NegotiateServiceCredential = messageSection.NegotiateServiceCredential, AlgorithmSuite = messageSection.AlgorithmSuite }; var transportSection = section.Security.Transport; var transport = new HttpTransportSecurity { ClientCredentialType = transportSection.ClientCredentialType, ProxyCredentialType = transportSection.ProxyCredentialType }; var wsHttpSecuritySection = section.Security; var wsHttpSecurity = new WSHttpSecurity { Mode = wsHttpSecuritySection.Mode, Transport = transport, Message = message }; ; binding.Security = wsHttpSecurity; if (readerQuotas != null) { binding.ReaderQuotas = readerQuotas; } binding.ReliableSession = reliableSession; configs.Add(binding); } return(configs); }
/// <summary> /// Creates a new instance of the <see cref="HttpBindingSecurity"/> class. /// </summary> public HttpBindingSecurity() { _mode = DefaultMode; _transportSecurity = new HttpTransportSecurity(); }
public static List <BasicHttpBinding> GetBasicHttpBindings(string exeConfigPath) { if (string.IsNullOrWhiteSpace(exeConfigPath)) { return(null); } var svcSection = Read.Config.ExeConfig.GetServiceModelSection(exeConfigPath); var configs = new List <BasicHttpBinding>(); foreach ( var section in svcSection.Bindings.BasicHttpBinding.ConfiguredBindings .Cast <BasicHttpBindingElement>()) { var df = new BasicHttpBinding(); var binding = new BasicHttpBinding { Name = section.Name, MaxBufferPoolSize = section.MaxBufferPoolSize > 0 ? section.MaxBufferPoolSize : df.MaxBufferPoolSize, MaxReceivedMessageSize = section.MaxReceivedMessageSize > 0 ? section.MaxReceivedMessageSize : df.MaxReceivedMessageSize, CloseTimeout = section.CloseTimeout != TimeSpan.Zero ? section.CloseTimeout : df.CloseTimeout, OpenTimeout = section.OpenTimeout != TimeSpan.Zero ? section.OpenTimeout : df.OpenTimeout, SendTimeout = section.SendTimeout != TimeSpan.Zero ? section.SendTimeout : df.SendTimeout, ReceiveTimeout = section.ReceiveTimeout != TimeSpan.Zero ? section.ReceiveTimeout : df.ReceiveTimeout, TextEncoding = section.TextEncoding ?? df.TextEncoding, MessageEncoding = section.MessageEncoding, AllowCookies = section.AllowCookies, BypassProxyOnLocal = section.BypassProxyOnLocal, HostNameComparisonMode = section.HostNameComparisonMode, UseDefaultWebProxy = section.UseDefaultWebProxy, }; var readerQuotasSection = section.ReaderQuotas; var readerQuotas = new System.Xml.XmlDictionaryReaderQuotas(); if (readerQuotasSection != null && readerQuotasSection.MaxDepth > 0) { readerQuotas.MaxDepth = readerQuotasSection.MaxDepth; readerQuotas.MaxStringContentLength = readerQuotasSection.MaxStringContentLength; readerQuotas.MaxArrayLength = readerQuotasSection.MaxArrayLength; readerQuotas.MaxBytesPerRead = readerQuotasSection.MaxBytesPerRead; readerQuotas.MaxNameTableCharCount = readerQuotasSection.MaxNameTableCharCount; } else { readerQuotas = null; } var messageSection = section.Security.Message; var message = new BasicHttpMessageSecurity { ClientCredentialType = messageSection.ClientCredentialType, AlgorithmSuite = messageSection.AlgorithmSuite, }; var transportSection = section.Security.Transport; var transport = new HttpTransportSecurity { ClientCredentialType = transportSection.ClientCredentialType, ProxyCredentialType = transportSection.ProxyCredentialType }; var basicHttpSecurity = new BasicHttpSecurity() { Message = message, Mode = section.Security.Mode, Transport = transport }; binding.Security = basicHttpSecurity; if (readerQuotas != null) { binding.ReaderQuotas = readerQuotas; } configs.Add(binding); } return(configs); }