gpt4 book ai didi

c# - WCF 客户端绑定(bind)以访问 https 服务。无法使用权​​限为 SSL/TLS 建立安全通道

转载 作者:太空宇宙 更新时间:2023-11-03 13:34:43 26 4
gpt4 key购买 nike

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

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

关于c# - WCF 客户端绑定(bind)以访问 https 服务。无法使用权​​限为 SSL/TLS 建立安全通道,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43848539/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com