本文整理汇总了C#中System.ServiceModel.BasicHttpBinding.CreateBindingElements方法的典型用法代码示例。如果您正苦于以下问题:C# BasicHttpBinding.CreateBindingElements方法的具体用法?C# BasicHttpBinding.CreateBindingElements怎么用?C# BasicHttpBinding.CreateBindingElements使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.ServiceModel.BasicHttpBinding
的用法示例。
在下文中一共展示了BasicHttpBinding.CreateBindingElements方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetBinding
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: DefaultValues
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");
}
示例3: Create_HttpBinding_SecurityMode_Without_SecurityBindingElement
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>();
}
示例4: SecurityMode4
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 ();
}
示例5: SecurityMode3
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);
}
}
示例6: SecurityMode2
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);
}
}
示例7: SecurityMode
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);
}
}
示例8: MessageEncoding
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.");
}
示例9: DefaultValueSecurityModeMessageError
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 ();
}