Ejemplo n.º 1
0
        public static void Snippet8()
        {
            // <Snippet8>
            BasicHttpBinding binding = new BasicHttpBinding();

            binding.Name = "binding1";
            binding.HostNameComparisonMode = HostNameComparisonMode.StrongWildcard;
            binding.Security.Mode          = BasicHttpSecurityMode.Message;

            // <Snippet9>
            BasicHttpSecurity        security    = binding.Security;
            BasicHttpMessageSecurity msgSecurity = security.Message;
            // </Snippet9>

            // <Snippet10>
            BasicHttpSecurityMode secMode = security.Mode;
            // </Snippet10>

            // <Snippet11>
            HttpTransportSecurity transSec = security.Transport;

            // </Snippet11>

            Console.WriteLine("The message-level security setting is {0}", secMode.ToString());
            Console.WriteLine("The transport-level security setting is {0}", transSec.ToString());
            // </Snippet8>
        }
Ejemplo n.º 2
0
        public void DefaultValueSecurityModeMessage()
        {
            BasicHttpBinding b = new BasicHttpBinding(BasicHttpSecurityMode.Message);

            b.Security.Message.ClientCredentialType = BasicHttpMessageCredentialType.Certificate;
            DefaultValues(b);

            // BasicHttpSecurity
            BasicHttpSecurity sec = b.Security;

            Assert.IsNotNull(sec, "#2-1");
            Assert.AreEqual(BasicHttpSecurityMode.Message, sec.Mode, "#2-2");
            BasicHttpMessageSecurity msg = sec.Message;

            Assert.IsNotNull(msg, "#2-3-1");
            Assert.AreEqual(SecurityAlgorithmSuite.Default, msg.AlgorithmSuite, "#2-3-2");
            Assert.AreEqual(BasicHttpMessageCredentialType.Certificate, msg.ClientCredentialType, "#2-3-3");
            HttpTransportSecurity trans = sec.Transport;

            Assert.IsNotNull(trans, "#2-4-1");
            Assert.AreEqual(HttpClientCredentialType.None, trans.ClientCredentialType, "#2-4-2");
            Assert.AreEqual(HttpProxyCredentialType.None, trans.ProxyCredentialType, "#2-4-3");
            Assert.AreEqual("", trans.Realm, "#2-4-4");

            // Binding elements
            BindingElementCollection bec = b.CreateBindingElements();

            Assert.AreEqual(3, bec.Count, "#5-1");
            Assert.AreEqual(typeof(AsymmetricSecurityBindingElement),
                            bec [0].GetType(), "#5-2");
            Assert.AreEqual(typeof(TextMessageEncodingBindingElement),
                            bec [1].GetType(), "#5-3");
            Assert.AreEqual(typeof(HttpTransportBindingElement),
                            bec [2].GetType(), "#5-4");
        }
Ejemplo n.º 3
0
 internal void InitializeFrom(BasicHttpMessageSecurity security)
 {
     if (security == null)
     {
         throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("security");
     }
     SetPropertyValueIfNotDefaultValue(ConfigurationStrings.ClientCredentialType, security.ClientCredentialType);
     SetPropertyValueIfNotDefaultValue(ConfigurationStrings.AlgorithmSuite, security.AlgorithmSuite);
 }
Ejemplo n.º 4
0
 internal void InitializeFrom(BasicHttpMessageSecurity security)
 {
     if (security == null)
     {
         throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("security");
     }
     this.ClientCredentialType = security.ClientCredentialType;
     this.AlgorithmSuite       = security.AlgorithmSuite;
 }
Ejemplo n.º 5
0
        internal void ApplyConfiguration(BasicHttpMessageSecurity security)
        {
            if (security == null)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof(security));
            }

            security.ClientCredentialType = this.ClientCredentialType;
        }
Ejemplo n.º 6
0
 internal void ApplyConfiguration(BasicHttpMessageSecurity security)
 {
     if (security == null)
     {
         throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("security");
     }
     security.ClientCredentialType = this.ClientCredentialType;
     if (PropertyValueOrigin.Default != this.ElementInformation.Properties[ConfigurationStrings.AlgorithmSuite].ValueOrigin)
     {
         security.AlgorithmSuite = this.AlgorithmSuite;
     }
 }
Ejemplo n.º 7
0
    public static void Default_Ctor_Initializes_Properties()
    {
        BasicHttpSecurity security = new BasicHttpSecurity();

        // These properties are not in a public contract
        BasicHttpSecurityMode expectedMode = BasicHttpSecurityMode.None;
        BasicHttpSecurityMode actualMode   = security.Mode;

        Assert.True(expectedMode == actualMode, String.Format("Mode expected: {0}, actual: {1}", expectedMode, actualMode));

        HttpTransportSecurity transportSecurity = security.Transport;

        Assert.True(transportSecurity != null, "Transport property should have been non-null");

        BasicHttpMessageSecurity httpSecurity = security.Message;

        Assert.True(httpSecurity != null, "Message property should have been non-null");
    }
Ejemplo n.º 8
0
        private static BasicHttpBinding CreateDefaultBinding()
        {
            BasicHttpBinding binding = new BasicHttpBinding();

            binding.CloseTimeout           = new TimeSpan(0, 1, 0);
            binding.OpenTimeout            = new TimeSpan(0, 1, 0);
            binding.SendTimeout            = new TimeSpan(0, 10, 0);
            binding.ReceiveTimeout         = new TimeSpan(0, 10, 0);
            binding.AllowCookies           = false;
            binding.BypassProxyOnLocal     = false;
            binding.HostNameComparisonMode = HostNameComparisonMode.StrongWildcard;
            binding.MaxBufferSize          = 65536;
            binding.MaxReceivedMessageSize = 65536L;
            binding.MaxBufferPoolSize      = 524288L;
            binding.MessageEncoding        = WSMessageEncoding.Text;
            binding.TextEncoding           = Encoding.UTF8;
            binding.TransferMode           = TransferMode.Buffered;
            binding.UseDefaultWebProxy     = true;
            XmlDictionaryReaderQuotas readerQuotas = new XmlDictionaryReaderQuotas();

            readerQuotas.MaxDepth = 32;
            readerQuotas.MaxStringContentLength = 8192;
            readerQuotas.MaxArrayLength         = 16384;
            readerQuotas.MaxBytesPerRead        = 4096;
            readerQuotas.MaxNameTableCharCount  = 16384;
            binding.ReaderQuotas = readerQuotas;
            BasicHttpSecurity security = new BasicHttpSecurity();

            security.Mode = BasicHttpSecurityMode.Transport;
            HttpTransportSecurity transport = new HttpTransportSecurity();

            transport.ClientCredentialType = HttpClientCredentialType.None;
            transport.ProxyCredentialType  = HttpProxyCredentialType.None;
            transport.Realm    = string.Empty;
            security.Transport = transport;
            BasicHttpMessageSecurity message = new BasicHttpMessageSecurity();

            message.ClientCredentialType = BasicHttpMessageCredentialType.UserName;
            message.AlgorithmSuite       = SecurityAlgorithmSuite.Default;
            security.Message             = message;
            binding.Security             = security;
            return(binding);
        }
Ejemplo n.º 9
0
        public static void Snippet5()
        {
            // <Snippet5>
            BasicHttpBinding binding = new BasicHttpBinding("myBinding");

            binding.Name = "binding1";
            binding.HostNameComparisonMode = HostNameComparisonMode.StrongWildcard;
            binding.Security.Mode          = BasicHttpSecurityMode.Message;

            // <Snippet6>
            BasicHttpSecurity        security    = binding.Security;
            BasicHttpMessageSecurity msgSecurity = security.Message;
            // </Snippet6>

            // <Snippet7>
            SecurityAlgorithmSuite         sas      = msgSecurity.AlgorithmSuite;
            BasicHttpMessageCredentialType credType = msgSecurity.ClientCredentialType;

            // </Snippet7>

            Console.WriteLine("The algorithm suite used is {0}", sas.ToString());
            Console.WriteLine("The client credential type used is {0}", credType.ToString());
            // </Snippet5>
        }
Ejemplo n.º 10
0
        private static MatrikkelKartServiceClient CreateMatrikkelKartServiceClient(string url, string username, string password)
        {
            var binding = new BasicHttpBinding
            {
                CloseTimeout           = new TimeSpan(0, 0, 1, 0),
                OpenTimeout            = new TimeSpan(0, 0, 1, 0),
                ReceiveTimeout         = new TimeSpan(0, 0, 10, 0),
                SendTimeout            = new TimeSpan(0, 0, 1, 0),
                AllowCookies           = false,
                BypassProxyOnLocal     = false,
                HostNameComparisonMode = HostNameComparisonMode.StrongWildcard,
                MaxBufferPoolSize      = 524288,
                MaxBufferSize          = 524288,
                MaxReceivedMessageSize = 524288,
                TextEncoding           = Encoding.UTF8,
                TransferMode           = TransferMode.Buffered,
                UseDefaultWebProxy     = true,
                MessageEncoding        = WSMessageEncoding.Text
            };

            var basicHttpSecurity = new BasicHttpSecurity {
                Mode = BasicHttpSecurityMode.TransportCredentialOnly
            };

            var httpTransportSecurity =
                new HttpTransportSecurity
            {
                ClientCredentialType = HttpClientCredentialType.Basic,
                ProxyCredentialType  = HttpProxyCredentialType.None,
                Realm = "default"
            };

            basicHttpSecurity.Transport = httpTransportSecurity;

            var basicHttpMessageSecurity =
                new BasicHttpMessageSecurity
            {
                ClientCredentialType = BasicHttpMessageCredentialType.UserName,
                AlgorithmSuite       = SecurityAlgorithmSuite.Default
            };

            basicHttpSecurity.Message = basicHttpMessageSecurity;

            binding.Security = basicHttpSecurity;

            var endpointAddress = new EndpointAddress(
                new Uri(url), AddressHeader.CreateAddressHeader("contract", "",
                                                                "GImatrikkelWS.MatrikkelkartPort.MatrikkelKartService"));

            return(new MatrikkelKartServiceClient(binding, endpointAddress)
            {
                ClientCredentials =
                {
                    UserName     =
                    {
                        UserName = username.ToLower(),
                        Password = password
                    }
                }
            });
        }
 /// <summary>
 /// Initializes a new instance.
 /// </summary>
 public AspNetCoreBasicBinding() :
     base()
 {
     messageSecurityElement = new BasicHttpMessageSecurity();
 }
Ejemplo n.º 12
0
        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);
        }