【发布时间】:2020-06-02 14:40:10
【问题描述】:
我想我需要弄清楚如何从服务引用中获取 httpclient。
我一直在连接到返回证书错误的 Web 服务。我想绕过那个错误,在 dotnet 框架中,这很简单。但是,在核心中,我被告知我必须获取 httpClient 并向其添加自定义处理程序。没关系,但是当我有一个 Web 服务的服务引用对象时,我不知道如何从中获取 httpClient。
首先,我添加了对 Web 服务(不是我控制的)的服务引用。
接下来,
BasicHttpBinding httpBinding = new BasicHttpBinding();
httpBinding.Security.Mode = BasicHttpSecurityMode.Transport;
httpBinding.Security.Transport.ClientCredentialType = HttpClientCredentialType.Basic;
httpBinding.Security.Transport.ProxyCredentialType = HttpProxyCredentialType.Basic;
SRI_CAP_AlertCollector.AlertCollectorServicePortClient client = new SRI_CAP_AlertCollector.AlertCollectorServicePortClient(httpBinding, endpoint);
但是当我调用其中一种服务方法(异步)时,由于证书而出现错误。 由于这是一个概念验证,我想绕过证书错误。
在 DotNetCore 中,这样做与使用 dotnet 框架不同。所以我试图弄清楚如何从服务引用中获取 httpClientHandler 以便我可以添加一个 ServerCertificateCustomValidationCallback
【问题讨论】:
-
嘿,Les,没有足够的信息可以离开这里。您能否添加一些代码并解释您要在更大的应用程序上下文中解决什么问题?
-
见上面添加的措辞。
标签: .net-core service-reference