Esempio n. 1
0
        public void MessageSecurityCertificateNego()
        {
            WSHttpBinding binding = new WSHttpBinding();

            binding.Security.Message.ClientCredentialType =
                MessageCredentialType.Certificate;
            SymmetricSecurityBindingElement sbe =
                binding.CreateBindingElements().Find <SymmetricSecurityBindingElement> ();

            Assert.IsNotNull(sbe, "#1");
            Assert.AreEqual(false, sbe.RequireSignatureConfirmation, "#1-2");

            SecureConversationSecurityTokenParameters sp =
                sbe.ProtectionTokenParameters
                as SecureConversationSecurityTokenParameters;

            Assert.IsNotNull(sp, "#2");
            SymmetricSecurityBindingElement spbe =
                sp.BootstrapSecurityBindingElement
                as SymmetricSecurityBindingElement;

            Assert.IsNotNull(spbe, "#3");
            SslSecurityTokenParameters p =
                spbe.ProtectionTokenParameters
                as SslSecurityTokenParameters;

            Assert.IsNotNull(p, "#4");
            Assert.AreEqual(SecurityTokenReferenceStyle.Internal,
                            p.ReferenceStyle, "#5");
            Assert.AreEqual(SecurityTokenInclusionMode.AlwaysToRecipient,
                            p.InclusionMode, "#6");
        }
Esempio n. 2
0
        public void MessageSecurityIssuedToken()
        {
            WSHttpBinding binding = new WSHttpBinding();

            binding.Security.Message.EstablishSecurityContext = false;
            binding.Security.Message.ClientCredentialType     =
                MessageCredentialType.IssuedToken;
            SymmetricSecurityBindingElement sbe =
                binding.CreateBindingElements().Find <SymmetricSecurityBindingElement> ();

            Assert.IsNotNull(sbe, "#1");
            Assert.AreEqual(0, sbe.EndpointSupportingTokenParameters.Signed.Count, "#1-1");
            Assert.AreEqual(1, sbe.EndpointSupportingTokenParameters.Endorsing.Count, "#1-2");
            Assert.AreEqual(0, sbe.EndpointSupportingTokenParameters.SignedEndorsing.Count, "#1-3");
            Assert.AreEqual(0, sbe.EndpointSupportingTokenParameters.SignedEncrypted.Count, "#1-4");
            IssuedSecurityTokenParameters p =
                sbe.EndpointSupportingTokenParameters.Endorsing [0]
                as IssuedSecurityTokenParameters;

            Assert.IsNotNull(p, "#2");
            Assert.IsNotNull(p.ClaimTypeRequirements, "#2-1");
            Assert.AreEqual(1, p.ClaimTypeRequirements.Count, "#2-2");
            ClaimTypeRequirement r = p.ClaimTypeRequirements [0];

            Assert.AreEqual(ClaimTypes.PPID, r.ClaimType, "#3-1");
            Assert.IsFalse(r.IsOptional, "#3-2");
        }
Esempio n. 3
0
        public void MessageSecurityUserName()
        {
            WSHttpBinding binding = new WSHttpBinding();

            binding.Security.Message.NegotiateServiceCredential = false;
            binding.Security.Message.EstablishSecurityContext   = false;
            binding.Security.Message.ClientCredentialType       =
                MessageCredentialType.UserName;
            SymmetricSecurityBindingElement sbe =
                binding.CreateBindingElements().Find <SymmetricSecurityBindingElement> ();

            Assert.IsNotNull(sbe, "#1");
            Assert.AreEqual(false, sbe.RequireSignatureConfirmation, "#1-2");

            X509SecurityTokenParameters sp =
                sbe.ProtectionTokenParameters
                as X509SecurityTokenParameters;

            Assert.IsNotNull(sp, "#2");
            Assert.AreEqual(SecurityTokenReferenceStyle.Internal,
                            sp.ReferenceStyle, "#3");
            Assert.AreEqual(SecurityTokenInclusionMode.Never,
                            sp.InclusionMode, "#4");

            UserNameSecurityTokenParameters up =
                sbe.EndpointSupportingTokenParameters.SignedEncrypted [0]
                as UserNameSecurityTokenParameters;

            Assert.AreEqual(SecurityTokenReferenceStyle.Internal,
                            up.ReferenceStyle, "#5");
            Assert.AreEqual(SecurityTokenInclusionMode.AlwaysToRecipient,
                            up.InclusionMode, "#6");
        }
Esempio n. 4
0
        public void DefaultHttpTransport()
        {
            WSHttpBinding b = new WSHttpBinding();

            foreach (BindingElement be in b.CreateBindingElements())
            {
                HttpTransportBindingElement tbe =
                    be as HttpTransportBindingElement;
                if (tbe == null)
                {
                    continue;
                }

                Assert.AreEqual(false, tbe.AllowCookies, "#1");
                Assert.AreEqual(AuthenticationSchemes.Anonymous, tbe.AuthenticationScheme, "#2");
                Assert.AreEqual(false, tbe.BypassProxyOnLocal, "#3");
                Assert.AreEqual(HostNameComparisonMode.StrongWildcard, tbe.HostNameComparisonMode, "#4");
                Assert.AreEqual(true, tbe.KeepAliveEnabled, "#5");
                Assert.AreEqual(false, tbe.ManualAddressing, "#6");
                Assert.AreEqual(0x80000, tbe.MaxBufferPoolSize, "#7");
                Assert.AreEqual(0x10000, tbe.MaxBufferSize, "#8");
                Assert.AreEqual(0x10000, tbe.MaxReceivedMessageSize, "#9");
                Assert.IsNull(tbe.ProxyAddress, "#10");
                Assert.AreEqual(AuthenticationSchemes.Anonymous, tbe.ProxyAuthenticationScheme, "#11");
                Assert.AreEqual("", tbe.Realm, "#12");
                Assert.AreEqual(TransferMode.Buffered, tbe.TransferMode, "#13");
                Assert.AreEqual(true, tbe.UseDefaultWebProxy, "#14");

                return;
            }
            Assert.Fail("No transport binding element.");
        }
Esempio n. 5
0
 public static void snippetCreateBindingElements()
 {
     //<Snippet9>
     WSHttpBinding            wsHttpBinding = new WSHttpBinding();
     BindingElementCollection beCollection  = wsHttpBinding.CreateBindingElements();
     //</Snippet9>
 }
Esempio n. 6
0
        public void MessageSecuritySPNego()
        {
            WSHttpBinding binding = new WSHttpBinding();
            SymmetricSecurityBindingElement sbe =
                binding.CreateBindingElements().Find <SymmetricSecurityBindingElement> ();

            Assert.IsNotNull(sbe, "#1");
            Assert.AreEqual(false, sbe.RequireSignatureConfirmation, "#1-2");

            SecureConversationSecurityTokenParameters sp =
                sbe.ProtectionTokenParameters
                as SecureConversationSecurityTokenParameters;

            Assert.IsNotNull(sp, "#2");
            SymmetricSecurityBindingElement spbe =
                sp.BootstrapSecurityBindingElement
                as SymmetricSecurityBindingElement;

            Assert.IsNotNull(spbe, "#3");
            SspiSecurityTokenParameters p =
                spbe.ProtectionTokenParameters
                as SspiSecurityTokenParameters;

            Assert.IsNotNull(p, "#4");
            Assert.AreEqual(SecurityTokenReferenceStyle.Internal,
                            p.ReferenceStyle, "#5");
            Assert.AreEqual(SecurityTokenInclusionMode.AlwaysToRecipient,
                            p.InclusionMode, "#6");
            Assert.AreEqual(0, sbe.EndpointSupportingTokenParameters.Signed.Count, "#7");
            Assert.AreEqual(0, sbe.EndpointSupportingTokenParameters.SignedEncrypted.Count, "#8");
            Assert.AreEqual(0, sbe.EndpointSupportingTokenParameters.Endorsing.Count, "#9");
            Assert.AreEqual(0, sbe.EndpointSupportingTokenParameters.SignedEndorsing.Count, "#10");
            Assert.AreEqual(0, spbe.EndpointSupportingTokenParameters.Signed.Count, "#11");
            Assert.AreEqual(0, spbe.EndpointSupportingTokenParameters.SignedEncrypted.Count, "#12");
            Assert.AreEqual(0, spbe.EndpointSupportingTokenParameters.Endorsing.Count, "#13");
            Assert.AreEqual(0, spbe.EndpointSupportingTokenParameters.SignedEndorsing.Count, "#14");

            Assert.AreEqual(0, sbe.OptionalEndpointSupportingTokenParameters.Signed.Count, "#17");
            Assert.AreEqual(0, sbe.OptionalEndpointSupportingTokenParameters.SignedEncrypted.Count, "#18");
            Assert.AreEqual(0, sbe.OptionalEndpointSupportingTokenParameters.Endorsing.Count, "#19");
            Assert.AreEqual(0, sbe.OptionalEndpointSupportingTokenParameters.SignedEndorsing.Count, "#110");
            Assert.AreEqual(0, spbe.OptionalEndpointSupportingTokenParameters.Signed.Count, "#21");
            Assert.AreEqual(0, spbe.OptionalEndpointSupportingTokenParameters.SignedEncrypted.Count, "#22");
            Assert.AreEqual(0, spbe.OptionalEndpointSupportingTokenParameters.Endorsing.Count, "#23");
            Assert.AreEqual(0, spbe.OptionalEndpointSupportingTokenParameters.SignedEndorsing.Count, "#24");
        }
Esempio n. 7
0
        private void ShowUse()
        {
            //<snippet17>
            // Create an instance of the binding to use.
            WSHttpBinding b = new WSHttpBinding();

            // Get the binding element collection.
            BindingElementCollection bec = b.CreateBindingElements();

            // Find the SymmetricSecurityBindingElement in the colllection.
            // Important: Cast to the SymmetricSecurityBindingElement when using the Find
            // method.
            SymmetricSecurityBindingElement sbe = (SymmetricSecurityBindingElement)
                                                  bec.Find <SecurityBindingElement>();

            // Get the LocalServiceSettings from the binding element.
            LocalServiceSecuritySettings lss = sbe.LocalServiceSettings;

            // Print out values.
            Console.WriteLine("DetectReplays: {0} days", lss.DetectReplays);
            Console.WriteLine("ReplayWindow: {0} minutes", lss.ReplayWindow.Minutes);
            Console.WriteLine("MaxClockSkew: {0} minutes", lss.MaxClockSkew.Minutes);

            Console.ReadLine();
            Console.WriteLine("Press Enter to Continue");
            // Change the MaxClockSkew to 3 minutes.
            lss.MaxClockSkew = new TimeSpan(0, 0, 3, 0);

            // Print the new value.
            Console.WriteLine("New MaxClockSkew: {0} minutes", lss.MaxClockSkew.Minutes);
            Console.WriteLine("Press Enter to End");
            Console.ReadLine();

            // Create a URI for the service.
            Uri httpUri = new Uri("http://localhost/calculator");

            // Create a ServiceHost. The binding has the changed MaxClockSkew.
            ServiceHost sh = new ServiceHost(typeof(Calculator), httpUri);

            sh.AddServiceEndpoint(typeof(ICalculator), b, "");
            // sh.Open();
            // Console.WriteLine("Listening");
            // Console.ReadLine();
            // sh.Close();
            //</snippet17>
        }
Esempio n. 8
0
        //Create a custom binding using a WsHttpBinding
        public static Binding CreateCustomSecurityBinding()
        {
            WSHttpBinding binding = new WSHttpBinding(SecurityMode.Message);

            //Clients are anonymous to the service
            binding.Security.Message.ClientCredentialType = MessageCredentialType.None;
            //Secure conversation is turned off for simplification. If secure conversation is turned on then
            //you also need to set the IdentityVerifier on the secureconversation bootstrap binding.
            binding.Security.Message.EstablishSecurityContext = false;

            //Get the SecurityBindingElement and cast to a SymmetricSecurityBindingElement to set the IdentityVerifier
            BindingElementCollection        outputBec = binding.CreateBindingElements();
            SymmetricSecurityBindingElement ssbe      = (SymmetricSecurityBindingElement)outputBec.Find <SecurityBindingElement>();

            //Set the Custom IdentityVerifier
            ssbe.LocalClientSettings.IdentityVerifier = new CustomIdentityVerifier();

            return(new CustomBinding(outputBec));
        }
Esempio n. 9
0
        private static Binding CreateWsBinding(bool allowSession, MessageCredentialType security = MessageCredentialType.None)
        {
            WSHttpBinding binding = new WSHttpBinding
            {
                AllowCookies           = true,
                BypassProxyOnLocal     = false,
                TransactionFlow        = false,
                MessageEncoding        = WSMessageEncoding.Text,
                TextEncoding           = Encoding.UTF8,
                UseDefaultWebProxy     = true,
                HostNameComparisonMode = HostNameComparisonMode.StrongWildcard,
                MaxReceivedMessageSize = Int32.MaxValue,
                ReceiveTimeout         = new TimeSpan(0, 0, ConnectionTimeout)
            };

            binding.ReliableSession.Enabled           = allowSession;
            binding.ReliableSession.Ordered           = false;
            binding.ReliableSession.InactivityTimeout = new TimeSpan(0, 0, ConnectionTimeout);

            binding.Security.Mode            = security == MessageCredentialType.None ? SecurityMode.None : SecurityMode.Message;
            binding.Security.Transport.Realm = String.Empty;
            binding.Security.Message.NegotiateServiceCredential = true;
            binding.Security.Message.ClientCredentialType       = security;

            binding.MaxBufferPoolSize      = Int32.MaxValue;
            binding.MaxReceivedMessageSize = Int32.MaxValue;
            binding.ReaderQuotas           = new XmlDictionaryReaderQuotas
            {
                MaxStringContentLength = Int32.MaxValue,
                MaxArrayLength         = Int32.MaxValue,
                MaxBytesPerRead        = Int32.MaxValue,
                MaxDepth = Int32.MaxValue,
                MaxNameTableCharCount = Int32.MaxValue
            };

            BindingElementCollection elements = binding.CreateBindingElements();

            EnableMultithreadingForReliableSessions(elements);
            return(new CustomBinding(elements)
            {
                ReceiveTimeout = new TimeSpan(0, 0, ConnectionTimeout)
            });
        }
Esempio n. 10
0
        public void DefaultTransactionFlow()
        {
            WSHttpBinding b = new WSHttpBinding();

            foreach (BindingElement be in b.CreateBindingElements())
            {
                TransactionFlowBindingElement tbe =
                    be as TransactionFlowBindingElement;
                if (tbe == null)
                {
                    continue;
                }

                Assert.AreEqual(TransactionProtocol.WSAtomicTransactionOctober2004,
                                tbe.TransactionProtocol, "#1");

                return;
            }
            Assert.Fail("No transaction flow binding element.");
        }
Esempio n. 11
0
        private void LocalClient()
        {
            //<snippet15>
            // Create an instance of the binding to use.
            WSHttpBinding b = new WSHttpBinding();

            // Get the binding element collection.
            BindingElementCollection bec = b.CreateBindingElements();

            // Find the SymmetricSecurityBindingElement in the collection.
            // Important: Cast to the SymmetricSecurityBindingElement when using the Find
            // method.
            SymmetricSecurityBindingElement sbe = (SymmetricSecurityBindingElement)
                                                  bec.Find <SecurityBindingElement>();

            // Get the LocalSecuritySettings from the binding element.
            LocalClientSecuritySettings lc = sbe.LocalClientSettings;

            // Print out values.
            Console.WriteLine("Maximum cookie caching time: {0} days", lc.MaxCookieCachingTime.Days);
            Console.WriteLine("Replay Cache Size: {0}", lc.ReplayCacheSize);
            Console.WriteLine("ReplayWindow: {0} minutes", lc.ReplayWindow.Minutes);
            Console.WriteLine("MaxClockSkew: {0} minutes", lc.MaxClockSkew.Minutes);
            Console.ReadLine();

            // Change the MaxClockSkew to 3 minutes.
            lc.MaxClockSkew = new TimeSpan(0, 0, 3, 0);

            // Print the new value.
            Console.WriteLine("New MaxClockSkew: {0} minutes", lc.MaxClockSkew.Minutes);
            Console.ReadLine();

            // Create an EndpointAddress for the service.
            EndpointAddress ea = new EndpointAddress("http://localhost/calculator");

            // Create a client. The binding has the changed MaxClockSkew.
            // CalculatorClient cc = new CalculatorClient(b, ea);
            // Use the new client. (Not shown.)
            // cc.Close();
            //</snippet15>
        }
Esempio n. 12
0
        public void DefaultValues()
        {
            WSHttpBinding b = new WSHttpBinding();

            // common tests
            DefaultValues(b, "http");

            // WSHttpSecurity
            WSHttpSecurity sec = b.Security;

            Assert.IsNotNull(sec, "#2-1");
            Assert.AreEqual(SecurityMode.Message, sec.Mode, "#2-2");
            // Security.Message
            NonDualMessageSecurityOverHttp msg = sec.Message;

            Assert.IsNotNull(msg, "#2-3");
            Assert.AreEqual(true, msg.EstablishSecurityContext, "#2-3-1");
            Assert.AreEqual(SecurityAlgorithmSuite.Default,
                            msg.AlgorithmSuite, "#2-3-2");
            // it is not worthy of test, just for checking default value.
            Assert.AreEqual(MessageCredentialType.Windows,
                            msg.ClientCredentialType, "#2-3-3");
            Assert.AreEqual(true, msg.NegotiateServiceCredential, "#2-3-4");
            // FIXME: test Security.Transport
            Assert.IsNotNull(sec.Transport, "#2-4");

            // Binding elements

            BindingElementCollection bec = b.CreateBindingElements();

            Assert.AreEqual(4, bec.Count, "#5-1");
            Assert.AreEqual(typeof(TransactionFlowBindingElement),
                            bec [0].GetType(), "#5-2");
            Assert.AreEqual(typeof(SymmetricSecurityBindingElement),
                            bec [1].GetType(), "#5-3");
            Assert.AreEqual(typeof(TextMessageEncodingBindingElement),
                            bec [2].GetType(), "#5-4");
            Assert.AreEqual(typeof(HttpTransportBindingElement),
                            bec [3].GetType(), "#5-5");
        }
Esempio n. 13
0
        public void DefaultMessageSecurity()
        {
            WSHttpBinding b = new WSHttpBinding();
            SymmetricSecurityBindingElement sbe = b.CreateBindingElements().Find <SymmetricSecurityBindingElement> ();

            Assert.IsNotNull(sbe, "#0");

            SecureConversationSecurityTokenParameters p =
                sbe.ProtectionTokenParameters as SecureConversationSecurityTokenParameters;

            Assert.IsNotNull(p, "#1");
            SymmetricSecurityBindingElement scbe =
                p.BootstrapSecurityBindingElement as SymmetricSecurityBindingElement;

            Assert.IsNotNull(scbe, "#1.1");
            // since the default w/o SecureConv is SSPI ...
            Assert.IsTrue(scbe.ProtectionTokenParameters is SspiSecurityTokenParameters, "#1.2");

            Assert.AreEqual(SecurityAlgorithmSuite.Default,
                            sbe.DefaultAlgorithmSuite, "#2");

            SupportingTokenParameters s =
                sbe.EndpointSupportingTokenParameters;

            Assert.IsNotNull(s, "#3");
            Assert.AreEqual(0, s.Endorsing.Count, "#3-1");
            Assert.AreEqual(0, s.Signed.Count, "#3-2");
            Assert.AreEqual(0, s.SignedEndorsing.Count, "#3-3");
            Assert.AreEqual(0, s.SignedEncrypted.Count, "#3-4");

            Assert.AreEqual(0, sbe.OperationSupportingTokenParameters.Count, "#4");

            s = sbe.OptionalEndpointSupportingTokenParameters;
            Assert.IsNotNull(s, "#5");
            Assert.AreEqual(0, s.Endorsing.Count, "#5-1");
            Assert.AreEqual(0, s.Signed.Count, "#5-2");
            Assert.AreEqual(0, s.SignedEndorsing.Count, "#5-3");
            Assert.AreEqual(0, s.SignedEncrypted.Count, "#5-4");
            Assert.AreEqual(0, sbe.OptionalOperationSupportingTokenParameters.Count, "#6");
        }
Esempio n. 14
0
        public void DefaultMessageEncoding()
        {
            WSHttpBinding b = new WSHttpBinding();

            foreach (BindingElement be in b.CreateBindingElements())
            {
                MessageEncodingBindingElement mbe =
                    be as MessageEncodingBindingElement;
                if (mbe == null)
                {
                    continue;
                }
                MessageEncoderFactory f = mbe.CreateMessageEncoderFactory();
                MessageEncoder        e = f.Encoder;

                Assert.AreEqual(typeof(TextMessageEncodingBindingElement), mbe.GetType(), "#1-1");
                Assert.AreEqual(MessageVersion.Default, f.MessageVersion, "#2-1");
                Assert.AreEqual("application/soap+xml; charset=utf-8", e.ContentType, "#3-1");
                Assert.AreEqual("application/soap+xml", e.MediaType, "#3-2");
                return;
            }
            Assert.Fail("No message encodiing binding element.");
        }
Esempio n. 15
0
        public void MessageSecurityNoSecureConversation()
        {
            WSHttpBinding b = new WSHttpBinding();

            b.Security.Message.EstablishSecurityContext = false;
            SymmetricSecurityBindingElement sbe = b.CreateBindingElements().Find <SymmetricSecurityBindingElement> ();

            Assert.IsNotNull(sbe, "#0");

            Assert.AreEqual(
                typeof(SspiSecurityTokenParameters),
                sbe.ProtectionTokenParameters.GetType(), "#1");
            // no worthy to check SSPI security as we never support it.

            b.Security.Message.ClientCredentialType = MessageCredentialType.None;
            sbe = b.CreateBindingElements().Find <SymmetricSecurityBindingElement> ();
            SslSecurityTokenParameters ssltp =
                sbe.ProtectionTokenParameters
                as SslSecurityTokenParameters;

            Assert.IsNotNull(ssltp, "#2-1");
            Assert.AreEqual(true, ssltp.RequireCancellation, "#2-2");
            Assert.AreEqual(false, ssltp.RequireClientCertificate, "#2-3");

            b.Security.Message.ClientCredentialType = MessageCredentialType.UserName;
            sbe   = b.CreateBindingElements().Find <SymmetricSecurityBindingElement> ();
            ssltp = sbe.ProtectionTokenParameters as SslSecurityTokenParameters;
            Assert.IsNotNull(ssltp, "#3-1");

            // No NegotiateServiceCredential modes ...

            b.Security.Message.NegotiateServiceCredential = false;
            b.Security.Message.ClientCredentialType       = MessageCredentialType.Windows;
            sbe = b.CreateBindingElements().Find <SymmetricSecurityBindingElement> ();
            KerberosSecurityTokenParameters ktp =
                sbe.ProtectionTokenParameters
                as KerberosSecurityTokenParameters;

            Assert.IsNotNull(ktp, "#4-1");
            // no worthy of testing windows-only Kerberos stuff

            b.Security.Message.ClientCredentialType = MessageCredentialType.None;
            sbe = b.CreateBindingElements().Find <SymmetricSecurityBindingElement> ();
            X509SecurityTokenParameters x509tp =
                sbe.ProtectionTokenParameters
                as X509SecurityTokenParameters;

            Assert.IsNotNull(x509tp, "#5-1");
            Assert.AreEqual(X509KeyIdentifierClauseType.Thumbprint, x509tp.X509ReferenceStyle, "#5-2");
            Assert.AreEqual(SecurityTokenInclusionMode.Never, x509tp.InclusionMode, "#5-3");

            b.Security.Message.ClientCredentialType = MessageCredentialType.Certificate;
            sbe = b.CreateBindingElements().Find <SymmetricSecurityBindingElement> ();
            Assert.AreEqual(1, sbe.EndpointSupportingTokenParameters.Endorsing.Count, "#6-0");
            x509tp = sbe.EndpointSupportingTokenParameters.Endorsing [0] as X509SecurityTokenParameters;
            Assert.IsNotNull(x509tp, "#6-1");
            Assert.AreEqual(X509KeyIdentifierClauseType.Thumbprint, x509tp.X509ReferenceStyle, "#6-2");
            Assert.AreEqual(SecurityTokenInclusionMode.AlwaysToRecipient, x509tp.InclusionMode, "#6-3");
            Assert.AreEqual(false, x509tp.RequireDerivedKeys, "#6-4");
            x509tp = sbe.ProtectionTokenParameters as X509SecurityTokenParameters;
            Assert.IsNotNull(x509tp, "#7-1");
            Assert.AreEqual(X509KeyIdentifierClauseType.Thumbprint, x509tp.X509ReferenceStyle, "#7-2");
            Assert.AreEqual(SecurityTokenInclusionMode.Never, x509tp.InclusionMode, "#7-3");
            Assert.AreEqual(true, x509tp.RequireDerivedKeys, "#7-4");
            Assert.AreEqual(true, sbe.RequireSignatureConfirmation, "#8");
        }
Esempio n. 16
0
        // Create and configure bindings within this EXE console application.
        public static void Main()
        {
            // Create a WSHttpBinding
            // <Snippet3>
            // <Snippet1>
            WSHttpBinding binding1 = new WSHttpBinding();

            // </Snippet1>

            binding1.BypassProxyOnLocal = true;
            // </Snippet3>

            // <Snippet4>
            EnvelopeVersion envelopeVersion =
                binding1.EnvelopeVersion;
            // </Snippet4>

            // <Snippet5>
            HostNameComparisonMode hostnameComparisonMode =
                binding1.HostNameComparisonMode;
            // </Snippet5>

            // <Snippet6>
            long maxBufferPoolSize =
                binding1.MaxBufferPoolSize;
            // </Snippet6>


            // <Snippet7>
            long maxReceivedMessageSize =
                binding1.MaxReceivedMessageSize;
            // </Snippet7>

            // <Snippet8>
            WSMessageEncoding messageEncoding =
                binding1.MessageEncoding;
            // </Snippet8>

            // <Snippet9>
            Uri proxyAddress =
                binding1.ProxyAddress;
            // </Snippet9>

            // <Snippet10>
            XmlDictionaryReaderQuotas readerQuotas =
                binding1.ReaderQuotas;
            // </Snippet10>

            // <Snippet11>
            OptionalReliableSession reliableSession =
                binding1.ReliableSession;
            // </Snippet11>

            // <Snippet12>
            string scheme = binding1.Scheme;
            // </Snippet12>

            // <Snippet13>
            Encoding textEncoding =
                binding1.TextEncoding;
            // </Snippet13>

            // <Snippet14>
            bool transactionFlow =
                binding1.TransactionFlow;
            // </Snippet14>

            // <Snippet15>
            bool useDefaultWebProxy =
                binding1.UseDefaultWebProxy;
            // </Snippet15>

            // <Snippet16>
            BindingElementCollection bindingElements =
                binding1.CreateBindingElements();

            // </Snippet16>



            // Set WSHttpBinding binding property values
            binding1.Name = "Binding1";
            binding1.HostNameComparisonMode =
                HostNameComparisonMode.StrongWildcard;
            binding1.Security.Mode           = SecurityMode.Message;
            binding1.ReliableSession.Enabled = false;
            binding1.TransactionFlow         = false;
            // binding1.Security.Message.DefaultProtectionLevel = System.Net.Security.ProtectionLevel.EncryptAndSign;

            // Enumerate properties of the binding1.
            Console.WriteLine("WSHttpBinding binding1 properties:");
            Console.WriteLine("      - name:\t\t\t{0}", binding1.Name);
            Console.WriteLine("      - hostname comparison:\t{0}", binding1.HostNameComparisonMode);
            Console.WriteLine("      - security mode:\t\t{0}", binding1.Security.Mode);
            Console.WriteLine("      - RM enabled:\t\t{0}", binding1.ReliableSession.Enabled);
            Console.WriteLine("      - transaction flow:\t{0}", binding1.TransactionFlow);
            //Console.WriteLine("      - message security:\t{0}", binding1.Security.Message.DefaultProtectionLevel);
            Console.WriteLine("      - transport scheme:\t{0}", binding1.Scheme);
            Console.WriteLine("      - max message size:\t{0}", binding1.MaxReceivedMessageSize);
            Console.WriteLine("      - default text encoding:\t{0}", binding1.TextEncoding);
            Console.WriteLine();

            // Create a WSFederationBinding with a message security mode
            // and with a reliable session enabled.
            WSFederationHttpBinding binding3 = new WSFederationHttpBinding(WSFederationHttpSecurityMode.Message, true);

            // Enumerate properties of the binding2.
            Console.WriteLine("WSFederationBinding binding3 properties:");
            Console.WriteLine("      - security mode:\t\t{0}", binding3.Security.Mode);
            Console.WriteLine("      - RM enabled:\t\t{0}", binding3.ReliableSession.Enabled);
            Console.WriteLine();
            Console.WriteLine("Press <ENTER> to terminate.");
            Console.ReadLine();
        }
Esempio n. 17
0
        /// <summary>
        /// Cria um binding para comunicação.
        /// </summary>
        /// <param name="securityMode">Modo de segurança.</param>
        /// <param name="requireClientCertificates"></param>
        /// <returns></returns>
        public static Binding CreateBinding(SecurityMode securityMode, bool requireClientCertificates)
        {
            WSHttpBinding binding = new WSHttpBinding(securityMode);

            binding.Security.Transport.ClientCredentialType = HttpClientCredentialType.None;
            binding.ReaderQuotas           = System.Xml.XmlDictionaryReaderQuotas.Max;
            binding.MaxReceivedMessageSize = System.Xml.XmlDictionaryReaderQuotas.Max.MaxStringContentLength;
            Binding binding2 = binding;

            if ((securityMode == SecurityMode.Transport) && requireClientCertificates)
            {
                binding.Security.Transport.ClientCredentialType = HttpClientCredentialType.Certificate;
                BindingElementCollection        bindingElementsInTopDownChannelStackOrder = binding.CreateBindingElements();
                TransportSecurityBindingElement item = new TransportSecurityBindingElement();
                System.ServiceModel.Security.Tokens.X509SecurityTokenParameters parameters = new System.ServiceModel.Security.Tokens.X509SecurityTokenParameters();
                parameters.InclusionMode = System.ServiceModel.Security.Tokens.SecurityTokenInclusionMode.AlwaysToRecipient;
                item.EndpointSupportingTokenParameters.Endorsing.Add(parameters);
                bindingElementsInTopDownChannelStackOrder.Insert(bindingElementsInTopDownChannelStackOrder.Count - 1, item);
                binding2 = new CustomBinding(bindingElementsInTopDownChannelStackOrder);
            }
            return(binding2);
        }