c# - 获取 "Could not create SSL/TLS secure channel"

标签 c# web-services azure soap tls1.2

我的一些网站有时无法连接到第 3 方 SOAP WS。当向第 3 方 WS 发出大量请求时,这种情况最常发生。因此,它并不是每次都会失败,只是有时会失败 - 而且大多数情况下是当向第 3 方发出大量请求时。

它已通过 IIS Crypto 在我们的本地服务器上修复。之前已选中所有禁用的复选框。

但是在 Azure WebApp 上我们无法控制这些设置 - 知道该怎么做吗?

这里是第 3 方 SOAP ws 的绑定(bind)代码和更多内容:

        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

最佳答案

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

关于c# - 获取 "Could not create SSL/TLS secure channel",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42696290/

相关文章:

c# - 带有自定义 ToolStripControlHost 的 ToolStrip 使 Tab 键顺序焦点行为怪异

C# Linq - 使用条件值排序并返回分组结果

android - 服务器上的网络服务调用不起作用

iOS 对 Web 服务器的身份验证

Azure Blob 备份

c# - 线程安全的OfType

c# - Reference Assemblies\Microsoft\Framework\.NETFramework\v4.0 中存储了哪些文件?

c# - 如何运行需要从 .NET Web 服务进行 AD 身份验证的命令行进程?

azure - Spring Boot Cosmos DB 实现中的动态查询

azure - 如何在 Azure Monitor 工作簿中创建缺失值(或零)的连续时间图表?