Пример #1
0
        /// <summary>Creates the Basic Binding to be used in the client.</summary>
        /// <returns></returns>
        private static BasicHttpBinding createBinding(string scheme)
        {
            BasicHttpBinding retBinding = new BasicHttpBinding();

            //Allow cookies and large messages
            retBinding.AllowCookies           = true;
            retBinding.MaxBufferSize          = Int32.MaxValue;
            retBinding.MaxBufferPoolSize      = Int32.MaxValue;
            retBinding.MaxReceivedMessageSize = Int32.MaxValue;
            retBinding.ReaderQuotas.MaxStringContentLength = Int32.MaxValue;
            retBinding.ReaderQuotas.MaxDepth              = Int32.MaxValue;
            retBinding.ReaderQuotas.MaxBytesPerRead       = Int32.MaxValue;
            retBinding.ReaderQuotas.MaxNameTableCharCount = Int32.MaxValue;
            retBinding.ReaderQuotas.MaxArrayLength        = Int32.MaxValue;
            retBinding.CloseTimeout           = new TimeSpan(1, 0, 0);
            retBinding.OpenTimeout            = new TimeSpan(1, 0, 0);
            retBinding.ReceiveTimeout         = new TimeSpan(1, 0, 0);
            retBinding.SendTimeout            = new TimeSpan(1, 0, 0);
            retBinding.BypassProxyOnLocal     = false;
            retBinding.HostNameComparisonMode = HostNameComparisonMode.StrongWildcard;
            retBinding.MessageEncoding        = WSMessageEncoding.Text;
            retBinding.TextEncoding           = System.Text.Encoding.UTF8;
            retBinding.TransferMode           = TransferMode.Buffered;
            retBinding.UseDefaultWebProxy     = true;
            retBinding.Security.Mode          = BasicHttpSecurityMode.None;
            retBinding.Security.Transport.ClientCredentialType = HttpClientCredentialType.None;
            retBinding.Security.Transport.ProxyCredentialType  = HttpProxyCredentialType.None;
            retBinding.Security.Message.ClientCredentialType   = BasicHttpMessageCredentialType.UserName;
            retBinding.Security.Message.AlgorithmSuite         = System.ServiceModel.Security.SecurityAlgorithmSuite.Default;

            //Handle SSL if necessary
            if (scheme == "https")
            {
                retBinding.Security.Mode = BasicHttpSecurityMode.Transport;
                retBinding.Security.Transport.ClientCredentialType = HttpClientCredentialType.None;

                //Allow self-signed certificates
                PermissiveCertificatePolicy.Enact("");
            }
            else
            {
                retBinding.Security.Mode = BasicHttpSecurityMode.None;
            }

            return(retBinding);
        }
Пример #2
0
 public static void Enact(string subjectName)
 {
     currentPolicy = new PermissiveCertificatePolicy(subjectName);
 }