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; }
public void DefaultValues () { BasicHttpBinding b = new BasicHttpBinding (); DefaultValues (b); // BasicHttpSecurity BasicHttpSecurity sec = b.Security; Assert.IsNotNull (sec, "#2-1"); Assert.AreEqual (BasicHttpSecurityMode.None, 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.UserName, 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 (2, bec.Count, "#5-1"); Assert.AreEqual (typeof (TextMessageEncodingBindingElement), bec [0].GetType (), "#5-2"); Assert.AreEqual (typeof (HttpTransportBindingElement), bec [1].GetType (), "#5-3"); }
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>(); }
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 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); } }
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); } }
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); } }
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."); }
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 (); }