예제 #1
0
        public static Binding GetBinding()
        {
            var binding = new BasicHttpBinding(BasicHttpSecurityMode.Transport);

            // Set binding timeout and other configuration settings
            binding.ReaderQuotas.MaxStringContentLength = int.MaxValue;
            binding.ReaderQuotas.MaxArrayLength         = int.MaxValue;
            binding.ReaderQuotas.MaxNameTableCharCount  = int.MaxValue;

            binding.ReceiveTimeout         = TimeSpan.MaxValue;
            binding.SendTimeout            = TimeSpan.MaxValue;
            binding.MaxReceivedMessageSize = int.MaxValue;

            var httpsTransportBindingElement = binding.CreateBindingElements().OfType <HttpsTransportBindingElement>().FirstOrDefault();

            if (httpsTransportBindingElement != null)
            {
                httpsTransportBindingElement.MaxPendingAccepts = 10000;     // Largest posible is 100000, otherwise throws
            }

            var httpTransportBindingElement = binding.CreateBindingElements().OfType <HttpTransportBindingElement>().FirstOrDefault();

            if (httpTransportBindingElement != null)
            {
                httpTransportBindingElement.MaxPendingAccepts = 10000;     // Largest posible is 100000, otherwise throws
            }

            return(binding);
        }
예제 #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");
        }
예제 #3
0
        public void snippet5()
        {
            // <Snippet5>
            BasicHttpBinding binding = new BasicHttpBinding();

            binding.Name      = "binding1";
            binding.Namespace = "http:\\My.ServiceModel.Samples";
            BindingElementCollection elements = binding.CreateBindingElements();
            // </Snippet5>

            Uri baseAddress = new Uri("http://localhost:8000/servicemodelsamples/service");
            Uri address     = new Uri("http://localhost:8000/servicemodelsamples/service/calc");

            // Create a ServiceHost for the ICalculator type and provide the base address.
            using (ServiceHost serviceHost = new ServiceHost(typeof(ICalculator), baseAddress))
            {
                serviceHost.AddServiceEndpoint(typeof(ICalculator), binding, address);

                // Open the ServiceHostBase to create listeners and start listening for messages.
                serviceHost.Open();

                // The service can now be accessed.
                Console.WriteLine("The service is ready.");
                Console.WriteLine("Press <ENTER> to terminate service.");
                Console.WriteLine();
                Console.ReadLine();
                // Close the ServiceHostBase to shutdown the service.
                serviceHost.Close();
            }
        }
        void BasicHttpBindingSecurityModeTransportPropertiesPropagated()
        {
            int    expectedMaxBufferSize          = 7654321;
            int    expectedMaxReceivedMessageSize = 87654321;
            string expectedScheme = "https";

            BasicHttpBinding binding = new BasicHttpBinding(BasicHttpSecurityMode.Transport);

            // Check the default values are as expected
            Assert.Equal(TransferMode.Buffered, binding.TransferMode);
            Assert.Equal(MessageVersion.Soap11, binding.MessageVersion);
            Assert.Equal(65536, binding.MaxReceivedMessageSize);
            Assert.Equal(65536, binding.MaxBufferSize);
            Assert.Equal(expectedScheme, binding.Scheme);

            binding.MaxBufferSize          = expectedMaxBufferSize;
            binding.MaxReceivedMessageSize = expectedMaxReceivedMessageSize;
            binding.TransferMode           = TransferMode.Streamed;

            BindingElementCollection    bindingElements = binding.CreateBindingElements();
            HttpTransportBindingElement htbe            = bindingElements.Find <HttpTransportBindingElement>();

            Assert.Equal("CoreWCF.Channels.HttpsTransportBindingElement", htbe.GetType().FullName);
            Assert.Equal(expectedMaxBufferSize, htbe.MaxBufferSize);
            Assert.Equal(expectedMaxReceivedMessageSize, htbe.MaxReceivedMessageSize);
            Assert.Equal(expectedScheme, htbe.Scheme);
            Assert.Equal(TransferMode.Streamed, htbe.TransferMode);
            MessageEncodingBindingElement mebe = bindingElements.Find <MessageEncodingBindingElement>();

            Assert.Equal("CoreWCF.Channels.TextMessageEncodingBindingElement", mebe.GetType().FullName);
            Assert.Equal(MessageVersion.Soap11, mebe.MessageVersion);
        }
예제 #5
0
        public void DefaultValueSecurityModeMessageError()
        {
            BasicHttpBinding b = new BasicHttpBinding(BasicHttpSecurityMode.Message);

            // "BasicHttp binding requires that BasicHttpBinding.Security.Message.ClientCredentialType be equivalent to the BasicHttpMessageCredentialType.Certificate credential type for secure messages. Select Transport or TransportWithMessageCredential security for UserName credentials."
            b.CreateBindingElements();
        }
예제 #6
0
        public static CustomBinding CreateCustomBinding()
        {
            ProxyUtils.ByPassCertificate();
            WSMessageEncoding msgEncoding;

            msgEncoding = WSMessageEncoding.Mtom;
            BasicHttpSecurityMode sec          = BasicHttpSecurityMode.TransportWithMessageCredential;
            BasicHttpBinding      basicBinding = new BasicHttpBinding(sec)
            {
                Security =
                {
                    Message                  =
                    {
                        ClientCredentialType = BasicHttpMessageCredentialType.UserName
                    }
                },
                MessageEncoding = msgEncoding,
            };
            var elements = basicBinding.CreateBindingElements();

            if (msgEncoding == WSMessageEncoding.Text)
            {
                TextMessageEncodingBindingElement te = elements.Find <TextMessageEncodingBindingElement>();
                te.MessageVersion = MessageVersion.Soap12;
            }
            else
            {
                MtomMessageEncodingBindingElement te = elements.Find <MtomMessageEncodingBindingElement>();
                te.MessageVersion = MessageVersion.Soap12;
            }
            CustomBinding customBinding = new CustomBinding(elements);

            return(customBinding);
        }
예제 #7
0
        Binding CreateBinding()
        {
            var binding  = new BasicHttpBinding(BasicHttpSecurityMode.TransportWithMessageCredential);
            var elements = binding.CreateBindingElements();

            elements.Find <SecurityBindingElement>().IncludeTimestamp = false;
            return(new CustomBinding(elements));
        }
예제 #8
0
        public void SecurityMode4()
        {
            var b = new BasicHttpBinding();

            b.Security.Mode = BasicHttpSecurityMode.TransportCredentialOnly;             // gives WS-Security message security.
            b.Security.Transport.ClientCredentialType = HttpClientCredentialType.Certificate;
            var bec = b.CreateBindingElements();
        }
    public static void ProxyCredentialType_Propagates_To_TransportBindingElement(HttpProxyCredentialType credentialType, AuthenticationSchemes mappedAuthScheme)
    {
        var binding = new BasicHttpBinding(BasicHttpSecurityMode.Transport);

        binding.Security.Transport.ProxyCredentialType = credentialType;
        var be   = binding.CreateBindingElements();
        var htbe = be.Find <HttpTransportBindingElement>();

        Assert.Equal(mappedAuthScheme, htbe.ProxyAuthenticationScheme);
    }
예제 #10
0
파일: client.cs 프로젝트: ruo2012/samples-1
        static void SnippetCreateBindingElements()
        {
            // from S_UEBinding\cs\Snippets.cs
            // <Snippet26>
            BasicHttpBinding binding = new BasicHttpBinding();

            binding.Name      = "binding1";
            binding.Namespace = "http:\\My.ServiceModel.Samples";
            BindingElementCollection elements = binding.CreateBindingElements();
            // </Snippet26>
        }
    public static void ExtendedProtectionPolicy_Propagates_To_TransportBindingElement()
    {
        var binding = new BasicHttpBinding(BasicHttpSecurityMode.Transport);
        var epp     = new ExtendedProtectionPolicy(PolicyEnforcement.Always);

        binding.Security.Transport.ExtendedProtectionPolicy = epp;
        var be   = binding.CreateBindingElements();
        var htbe = be.Find <HttpTransportBindingElement>();

        Assert.Equal(epp, htbe.ExtendedProtectionPolicy);
    }
    public static void Create_HttpBinding_SecurityMode_Without_SecurityBindingElement(BasicHttpSecurityMode securityMode)
    {
        BasicHttpBinding binding = new BasicHttpBinding(securityMode);
        var bindingElements      = binding.CreateBindingElements();

        var securityBindingElement = bindingElements.FirstOrDefault(x => x is SecurityBindingElement) as SecurityBindingElement;

        Assert.True(securityBindingElement == null, string.Format("securityBindingElement should be null when BasicHttpSecurityMode is '{0}'", securityMode));

        Assert.True(binding.CanBuildChannelFactory <IRequestChannel>(), string.Format("CanBuildChannelFactory should return true for BasicHttpSecurityMode:'{0}'", securityMode));
        binding.BuildChannelFactory <IRequestChannel>();
    }
예제 #13
0
        /// <summary>
        /// Inicializa el Binding por unica vez
        /// </summary>
        private Binding GetBinding()
        {
            //ServicePointManager.UseNagleAlgorithm = true;
            //ServicePointManager.Expect100Continue = false;
            //ServicePointManager.CheckCertificateRevocationList = false;
            //ServicePointManager.ServerCertificateValidationCallback = delegate { return true; };
            //ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls; // Activar por tls sino funciona con ssl3

            var binding  = new BasicHttpBinding(BasicHttpSecurityMode.Transport);
            var elements = binding.CreateBindingElements();

            return(new CustomBinding(elements));
        }
예제 #14
0
        public void CreateBindingElements()
        {
            BasicHttpBinding b = CreateBindingFromConfig();

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

            Assert.AreEqual(2, bec.Count, "#1");
            Assert.AreEqual(typeof(TextMessageEncodingBindingElement),
                            bec [0].GetType(), "#2");
            Assert.AreEqual(typeof(HttpTransportBindingElement),
                            bec [1].GetType(), "#3");
        }
예제 #15
0
        /// <summary>
        /// Inicializa el Binding por unica vez
        /// </summary>
        private static Binding GetBinding()
        {
            ServicePointManager.UseNagleAlgorithm = true;
            ServicePointManager.Expect100Continue = false;
            ServicePointManager.CheckCertificateRevocationList      = false;
            ServicePointManager.ServerCertificateValidationCallback = delegate { return(true); };
            ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls;

            var binding  = new BasicHttpBinding(BasicHttpSecurityMode.TransportWithMessageCredential);
            var elements = binding.CreateBindingElements();

            elements.Find <SecurityBindingElement>().EnableUnsecuredResponse = true;
            return(new CustomBinding(elements));
        }
예제 #16
0
        public void Elements_MessageEncodingBindingElement()
        {
            BasicHttpBinding                  b   = CreateBindingFromConfig();
            BindingElementCollection          bec = b.CreateBindingElements();
            TextMessageEncodingBindingElement m   =
                (TextMessageEncodingBindingElement)bec [0];

            Assert.AreEqual(64, m.MaxReadPoolSize, "#1");
            Assert.AreEqual(16, m.MaxWritePoolSize, "#2");
            Assert.AreEqual(4096, m.ReaderQuotas.MaxArrayLength, "#3");
            Assert.AreEqual(8192, m.ReaderQuotas.MaxBytesPerRead, "#4");
            Assert.AreEqual(64, m.ReaderQuotas.MaxDepth, "#5");
            Assert.AreEqual(8192, m.ReaderQuotas.MaxNameTableCharCount, "#6");
            Assert.AreEqual(16384, m.ReaderQuotas.MaxStringContentLength, "#7");
            Assert.AreEqual(Encoding.Unicode, m.WriteEncoding, "#8");
        }
예제 #17
0
        public void SecurityMode2()
        {
            var modes = new HttpClientCredentialType [] { HttpClientCredentialType.None, HttpClientCredentialType.Basic, HttpClientCredentialType.Digest, HttpClientCredentialType.Ntlm, HttpClientCredentialType.Windows, HttpClientCredentialType.Certificate };

            foreach (var m in modes)
            {
                var b = new BasicHttpBinding();
                b.Security.Mode = BasicHttpSecurityMode.TransportWithMessageCredential;                 // gives WS-Security message security.
                b.Security.Transport.ClientCredentialType = m;
                var bec = b.CreateBindingElements();
                Assert.AreEqual(3, bec.Count, "#1." + m);
                Assert.IsTrue(bec [0] is TransportSecurityBindingElement, "#2." + m);
                Assert.IsTrue(bec [2] is HttpsTransportBindingElement, "#3." + m);
                var tbe = (HttpsTransportBindingElement)bec [2];
                Assert.IsFalse(tbe.RequireClientCertificate, "#4." + m);
            }
        }
예제 #18
0
        public void SecurityMode3()
        {
            var modes = new HttpClientCredentialType [] { HttpClientCredentialType.None, HttpClientCredentialType.Basic, HttpClientCredentialType.Digest, HttpClientCredentialType.Ntlm, HttpClientCredentialType.Windows };
            var auths = new AuthenticationSchemes [] { AuthenticationSchemes.Anonymous, AuthenticationSchemes.Basic, AuthenticationSchemes.Digest, AuthenticationSchemes.Ntlm, AuthenticationSchemes.Negotiate };             // specifically, none->anonymous, and windows->negotiate

            for (int i = 0; i < modes.Length; i++)
            {
                var m = modes [i];
                var b = new BasicHttpBinding();
                b.Security.Mode = BasicHttpSecurityMode.TransportCredentialOnly;                 // gives WS-Security message security.
                b.Security.Transport.ClientCredentialType = m;
                var bec = b.CreateBindingElements();
                Assert.AreEqual(2, bec.Count, "#1." + m);
                Assert.IsTrue(bec [1] is HttpTransportBindingElement, "#2." + m);
                var tbe = (HttpTransportBindingElement)bec [1];
                Assert.AreEqual(auths [i], tbe.AuthenticationScheme, "#3." + m);
            }
        }
예제 #19
0
        public static Binding GetBufferedModHttp1Binding()
        {
            BasicHttpBinding            basicHttpBinding            = new BasicHttpBinding();
            HttpTransportBindingElement httpTransportBindingElement = basicHttpBinding.CreateBindingElements().Find <HttpTransportBindingElement>();
            MessageVersion messageVersion = basicHttpBinding.MessageVersion;
            MessageEncodingBindingElement encodingBindingElement = new BinaryMessageEncodingBindingElement();

            httpTransportBindingElement.TransferMode = TransferMode.Streamed;
            return(new CustomBinding(new BindingElement[]
            {
                encodingBindingElement,
                httpTransportBindingElement
            })
            {
                SendTimeout = TimeSpan.FromMinutes(20.0),
                ReceiveTimeout = TimeSpan.FromMinutes(20.0),
                OpenTimeout = TimeSpan.FromMinutes(20.0),
                CloseTimeout = TimeSpan.FromMinutes(20.0)
            });
        }
        private RightNowSyncPortChannel getChannel()
        {
            Binding binding = new BasicHttpBinding(BasicHttpSecurityMode.TransportWithMessageCredential);

            ((BasicHttpBinding)binding).Security.Message.ClientCredentialType = BasicHttpMessageCredentialType.UserName;
            ((BasicHttpBinding)binding).MaxBufferSize          = 1024 * 1024 * 1024;
            ((BasicHttpBinding)binding).MaxReceivedMessageSize = 1024 * 1024 * 1024;
            BindingElementCollection elements = binding.CreateBindingElements();

            elements.Find <SecurityBindingElement>().IncludeTimestamp = false;

            binding = new CustomBinding(elements);

            var channelFactory = new ChannelFactory <RightNowSyncPortChannel>(binding, new EndpointAddress(_globalContext.GetInterfaceServiceUrl(ConnectServiceType.Soap)));

            _globalContext.PrepareConnectSession(channelFactory);
            var rightNowChannel = channelFactory.CreateChannel();

            return(rightNowChannel);
        }
예제 #21
0
        public void MessageEncoding()
        {
            BasicHttpBinding b = new BasicHttpBinding();

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

                    Assert.AreEqual(typeof(TextMessageEncodingBindingElement), mbe.GetType(), "#1-1");
                    Assert.AreEqual(MessageVersion.Soap11, f.MessageVersion, "#2-1");
                    Assert.AreEqual("text/xml; charset=utf-8", e.ContentType, "#3-1");
                    Assert.AreEqual("text/xml", e.MediaType, "#3-2");
                    return;
                }
            }
            Assert.Fail("No message encodiing binding element.");
        }
예제 #22
0
        public void Elements_TransportBindingElement()
        {
            BasicHttpBinding            b   = CreateBindingFromConfig();
            BindingElementCollection    bec = b.CreateBindingElements();
            HttpTransportBindingElement t   =
                (HttpTransportBindingElement)bec [1];

            Assert.AreEqual(true, t.AllowCookies, "#1");
            Assert.AreEqual(AuthenticationSchemes.Anonymous, t.AuthenticationScheme, "#2");
            Assert.AreEqual(true, t.BypassProxyOnLocal, "#3");
            Assert.AreEqual(HostNameComparisonMode.Exact, t.HostNameComparisonMode, "#4");
            Assert.AreEqual(true, t.KeepAliveEnabled, "#5");
            Assert.AreEqual(false, t.ManualAddressing, "#6");
            Assert.AreEqual(262144, t.MaxBufferPoolSize, "#7");
            Assert.AreEqual(32768, t.MaxBufferSize, "#8");
            Assert.AreEqual(32768, t.MaxReceivedMessageSize, "#9");
            Assert.AreEqual("proxy", t.ProxyAddress.ToString(), "#10");
            Assert.AreEqual(AuthenticationSchemes.Anonymous, t.ProxyAuthenticationScheme, "#11");
            Assert.AreEqual("", t.Realm, "#12");
            Assert.AreEqual("http", t.Scheme, "#13");
            Assert.AreEqual(TransferMode.Streamed, t.TransferMode, "#14");
            Assert.AreEqual(false, t.UnsafeConnectionNtlmAuthentication, "#15");
            Assert.AreEqual(false, t.UseDefaultWebProxy, "#16");
        }
예제 #23
0
        public void SecurityMode()
        {
            // hmm, against my expectation, those modes does not give Http(s)TransportBindingElement property differences..
            var modes = new HttpClientCredentialType [] { HttpClientCredentialType.None, HttpClientCredentialType.Basic, HttpClientCredentialType.Digest, HttpClientCredentialType.Ntlm, HttpClientCredentialType.Windows, HttpClientCredentialType.Certificate };

            foreach (var m in modes)
            {
                var b = new BasicHttpBinding();
                b.Security.Mode = BasicHttpSecurityMode.Transport;
                b.Security.Transport.ClientCredentialType = m;
                var bec = b.CreateBindingElements();
                Assert.AreEqual(2, bec.Count, "#1." + m);
                Assert.IsTrue(bec [1] is HttpsTransportBindingElement, "#2." + m);
                var tbe = (HttpsTransportBindingElement)bec [1];
                if (m == HttpClientCredentialType.Certificate)
                {
                    Assert.IsTrue(tbe.RequireClientCertificate, "#3." + m);
                }
                else
                {
                    Assert.IsFalse(tbe.RequireClientCertificate, "#3." + m);
                }
            }
        }