【问题标题】:WCF client binding to access https service. Could not establish secure channel for SSL/TLS with authorityWCF 客户端绑定以访问 https 服务。无法为具有权限的 SSL/TLS 建立安全通道
【发布时间】:2017-10-06 12:12:37
【问题描述】:

我需要创建 WCF 客户端来连接通过 https 可用的服务。 当前负责 WCF 的客户端配置如下所示:

<wsHttpBinding>
  <binding name="TestBinding">
    <security mode="Transport">
        <transport clientCredentialType="None" />
    </security>
  </binding>
</wsHttpBinding>
<client>
   <endpoint address="https://address/etc" binding="wsHttpBinding" bindingConfiguration="TestBinding" contract="TestService.Test" name="TestName"/>
</client>

很遗憾,我遇到了一个错误:

Exception: System.ServiceModel.Security.SecurityNegotiationException
Message: Could not establish secure channel for SSL/TLS with authority 'address'.
Source: mscorlib

Server stack trace: 
   at System.ServiceModel.Channels.HttpChannelUtilities.ProcessGetResponseWebException(WebException webException, HttpWebRequest request, HttpAbortReason abortReason)
   at System.ServiceModel.Channels.HttpChannelFactory`1.HttpRequestChannel.HttpChannelRequest.WaitForReply(TimeSpan timeout)
   at System.ServiceModel.Channels.RequestChannel.Request(Message message, TimeSpan timeout)
   at System.ServiceModel.Dispatcher.RequestChannelBinder.Request(Message message, TimeSpan timeout)
   at System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean oneway, ProxyOperationRuntime operation, Object[] ins, Object[] outs, TimeSpan timeout)
   at System.ServiceModel.Channels.ServiceChannelProxy.InvokeService(IMethodCallMessage methodCall, ProxyOperationRuntime operation)
   at System.ServiceModel.Channels.ServiceChannelProxy.Invoke(IMessage message)

Exception rethrown at [0]: 
   at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg)
   at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type)
...

Nested Exception

Exception: System.Net.WebException
Message: The request was aborted: Could not create SSL/TLS secure channel.
Source: System
   at System.Net.HttpWebRequest.GetResponse()
   at System.ServiceModel.Channels.HttpChannelFactory`1.HttpRequestChannel.HttpChannelRequest.WaitForReply(TimeSpan timeout)

我无权修改此服务

更新:

出于测试目的,我忽略了 Application_Start 中 global.asax 中的证书,但我仍然遇到相同的异常

protected void Application_Start(object sender, EventArgs e) {
   ServicePointManager.ServerCertificateValidationCallback = delegate { return true; };
}

【问题讨论】:

    标签: c# wcf ssl https wcf-binding


    【解决方案1】:

    不受信任的证书可能会导致这种情况。 在调用你的服务之前试试这个:

    protected void BypassCertificateError()
    {
        ServicePointManager.ServerCertificateValidationCallback = delegate (object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors) { return true; };
    }
    

    但请注意,这不是一个好的做法,因为它完全忽略了服务器证书。

    【讨论】:

    • 我在调用之前有这个,我也有在 ApplicationStart 但仍然得到同样的异常。 ServicePointManager.ServerCertificateValidationCallback = 委托 { 返回真; };
    • 您可能正在使用 WCFTestClient。不幸的是 WCFTestClient 不支持不受信任的证书。您可以使用 SOAP UI 来测试您的服务。
    • 我正在使用代码中的客户端。它由 AddServiceReference 生成。这不是 wcftestclient
    • 如果它是公共网络服务,请提供调用服务所需的信息。希望能帮到你。
    • 不幸的是,它的服务只能在我的公司内部使用
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-02-12
    • 2015-04-05
    • 2017-08-23
    • 2011-05-26
    • 2014-11-26
    • 2019-12-05
    • 2018-04-21
    相关资源
    最近更新 更多