繁体   English   中英

WCF客户端绑定以访问https服务。 无法为具有权限的SSL / TLS建立安全通道

[英]WCF client binding to access https service. Could not establish secure channel for SSL/TLS with authority

我需要创建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; };
}

不受信任的证书可能导致此问题。 在致电您的服务之前尝试这个:

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

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM