获取“无法创建SSL/TLS安全通道”

问题描述:

我有些网站在连接到第三方SOAP WS时失败了。当第三方WS有很多请求时,这种情况发生得最多。所以它不会每次都失败,只有一些时候 - 而且大多数时候对第三方ws有很多要求。获取“无法创建SSL/TLS安全通道”

它已在我们的使用IIS Crypto的内部服务器上修复。所有禁用的复选框之前都被检查过。

但是在Azure WebApp上,我们无法控制这些设置 - 任何想法该怎么办?

继承人是结合多向第三方肥皂WS的代码:

 public static CustomBinding GetDefaultBinding() 
    { 
     ServicePointManager.ServerCertificateValidationCallback = delegate { return true; }; 

     AsymmetricSecurityBindingElement securityElement = new AsymmetricSecurityBindingElement(); 

     securityElement.MessageSecurityVersion = MessageSecurityVersion.WSSecurity11WSTrust13WSSecureConversation13WSSecurityPolicy12; 

     securityElement.InitiatorTokenParameters = new X509SecurityTokenParameters(X509KeyIdentifierClauseType.IssuerSerial, SecurityTokenInclusionMode.Never); 
     securityElement.RecipientTokenParameters = new X509SecurityTokenParameters(X509KeyIdentifierClauseType.IssuerSerial, SecurityTokenInclusionMode.Never); 
     securityElement.ProtectTokens = true; 

     securityElement.MessageProtectionOrder = MessageProtectionOrder.SignBeforeEncrypt; 

     securityElement.RequireSignatureConfirmation = true; 

     securityElement.SecurityHeaderLayout = SecurityHeaderLayout.Lax; 
     securityElement.EnableUnsecuredResponse = true; 
     securityElement.IncludeTimestamp = true; 
     securityElement.SetKeyDerivation(false); 
     securityElement.DefaultAlgorithmSuite = SecurityAlgorithmSuite.Basic128Rsa15; 
     securityElement.EndpointSupportingTokenParameters.SignedEncrypted.Add(new UserNameSecurityTokenParameters()); 
     securityElement.AllowSerializedSigningTokenOnReply = true; 

     CustomBinding myBinding = new CustomBinding(); 
     myBinding.Elements.Add(securityElement); 

     TextMessageEncodingBindingElement element = new TextMessageEncodingBindingElement(MessageVersion.Soap11WSAddressing10, Encoding.UTF8); 
     element.ReaderQuotas.MaxStringContentLength = int.MaxValue; 
     element.ReaderQuotas.MaxDepth = int.MaxValue; 
     element.ReaderQuotas.MaxArrayLength = int.MaxValue; 
     element.ReaderQuotas.MaxBytesPerRead = int.MaxValue; 
     element.ReaderQuotas.MaxNameTableCharCount = int.MaxValue; 
     myBinding.Elements.Add(element); 

     HttpsTransportBindingElement httpsBindingElement = new HttpsTransportBindingElement(); 
     httpsBindingElement.RequireClientCertificate = true; 
     httpsBindingElement.MaxBufferPoolSize = int.MaxValue; 
     httpsBindingElement.MaxBufferSize = int.MaxValue; 
     httpsBindingElement.MaxReceivedMessageSize = int.MaxValue; 
     httpsBindingElement.KeepAliveEnabled = false; 
     httpsBindingElement.AllowCookies = false; 

     myBinding.Elements.Add(httpsBindingElement); 

     myBinding.CloseTimeout = new TimeSpan(0, 10, 0); 
     myBinding.ReceiveTimeout = new TimeSpan(0, 10, 0); 
     myBinding.SendTimeout = new TimeSpan(0, 10, 0); 

     return myBinding; 
    } 

     private void ConfigureClientCredentials(ClientCredentials cc) 
    { 
     if (cc == null) return; 

     cc.UserName.UserName = Options.WebserviceUsername; 
     cc.UserName.Password = Options.AuthPassword; 

     cc.ClientCertificate.Certificate = Options.ClientCertificate; 
     cc.ServiceCertificate.DefaultCertificate = Options.IbaCertificate; 

     cc.ServiceCertificate.Authentication.CertificateValidationMode = X509CertificateValidationMode.None; 
    } 

    private void ConfigureEndPoint(ServiceEndpoint endpoint) 
    { 
     endpoint.Contract.ProtectionLevel = ProtectionLevel.EncryptAndSign; 
     endpoint.EndpointBehaviors.Add(new CustomEndpointBehavior()); 

    } 

All disabled checkbox was checked before

All disabled checkbox was checked before

第三方SOAP WS与错误的SSL/chipers上配置一台服务器(负载平衡器设置),导致了问题 - 所以这不是我的代码中的问题。

+0

对不起 - 我刚刚更新了我的答案:-) – pajzo

+0

这很快 - 太棒了。最后一个提示:我想你可能想阅读Clean Code(Robert Martin的伟大书籍)。你的代码可能会从中受益。 – GhostCat