You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

ASP.NET MVC调用WCF服务报错:无法建立SSL/TLS安全通道

WCF服务在ASP.NET MVC5中无法建立SSL/TLS安全通道(控制台调用正常)

两天前一切运行正常,且未修改任何代码。无需在服务器或本地计算机安装SSL证书,WCF服务的URL(https://sampleurl.com/service.svc)可在浏览器正常打开。控制台应用测试调用服务正常,但在ASP.NET MVC5项目中调用失败。

服务调用代码

CustomerServiceClient client = new CustomerServiceClient();
client.ClientCredentials.UserName.UserName = "test@asfasf.com";
client.ClientCredentials.UserName.Password = "asfasf";

var result = client.GetInformation("1MS0274796");

报错信息

System.ServiceModel.Security.SecurityNegotiationException: 'Could not establish secure channel for SSL/TLS with authority 'servis.vatanbilgisayar.com'.'

Inner Exception: WebException: The request was aborted: Could not create SSL/TLS secure channel.

已尝试的解决方案

调用服务前添加以下代码,但无效:

ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;

添加证书验证回调后出现新错误:

System.Net.ServicePointManager.ServerCertificateValidationCallback +=
    (se, cert, chain, sslerror) =>
        {
            return true;
        };

新错误信息:

The certificate key algorithm is not supported

项目web.config配置

<system.serviceModel>
    <bindings>
        <wsHttpBinding>
            <binding name="CustomerServiceSoap">
                <security mode="TransportWithMessageCredential">
                    <transport clientCredentialType="None" />
                    <message clientCredentialType="UserName" />
                </security>
            </binding>
        </wsHttpBinding>
    </bindings>
    <client>
        <endpoint address="https://xyzx.com/CustomerService.svc"
                  binding="wsHttpBinding" 
                  bindingConfiguration="CustomerServiceSoap"
                  contract="xfasf.asfasf" name="CustomerServiceSoap" />
    </client>
</system.serviceModel>

更新

经排查发现,调用服务时需显式调用Open()和Close()方法。若多次调用时未执行此操作,服务可能完全无响应。此前从未出现该问题,此次为突然发生。

内容的提问来源于stack exchange,提问作者MonkeyDLuffy

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.20 10:25:06