wcf - WCF 服务调用错误消息无法为具有权限的 SSL/TLS 建立安全通道
问题描述
您好,我正在尝试调用网络服务:-
https://example.com/Dealio/DealioCapLinkSvc.svc
(实际名称隐藏)。
我可以在浏览器上浏览此服务。但是,当我通过客户端应用程序调用服务时,出现以下错误:-
Could not establish secure channel for SSL/TLS with authority 'example.com'.
谁能告诉我发生了什么?
以下是应用程序配置:-
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="SOAPEndPoint1" />
</basicHttpBinding>
</bindings>
<client>
<endpoint address="http://example.com/dealio/DealioCapLinkSvc.svc/soap"
binding="basicHttpBinding" bindingConfiguration="SOAPEndPoint1"
behaviorConfiguration="authBehavior"
contract="DealioService.IDealioLib" name="SOAPEndPoint1" />
</client>
<behaviors>
<serviceBehaviors>
<behavior>
<serviceMetadata httpGetEnabled="True" httpsGetEnabled="True" />
<serviceDebug includeExceptionDetailInFaults="False" />
</behavior>
</serviceBehaviors>
<!-- Security Behavior -->
<endpointBehaviors>
<behavior name="authBehavior">
<authBehavior />
</behavior>
</endpointBehaviors>
</behaviors>
<extensions>
<behaviorExtensions>
<add name="authBehavior" type="CanadaDealio.AuthBehavior, CanadaDealio , Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" />
</behaviorExtensions>
</extensions>
</system.serviceModel>
</configuration>
这是调用服务的代码:-
static void Main(string[] args)
{
Deal deal = new Deal();
deal = PopulateDealDetails(deal);
DealReturnResults dealioReturnResults = null;
DealioLibClient dealioServiceProxy = new DealioLibClient();
try
{
ValidationErrorList validationErrorList =
dealioServiceProxy.ValidateDealDetails(deal);
}
catch(Exception e)
{
}
}
谁能告诉我发生了什么?我不认为这应该很难调用 WCF 服务。
解决方案
通过添加服务引用调用 Web 服务时,尝试添加以下代码片段。
客户端。
ServicePointManager.ServerCertificateValidationCallback = (sender, certificate, chain, sslPolicyErrors) => true;
ServiceReference1.ServiceClient client = new ServiceReference1.ServiceClient();
client.ClientCredentials.ServiceCertificate.Authentication.CertificateValidationMode = System.ServiceModel.Security.X509CertificateValidationMode.None;
try
{
var result = client.SayHello();
Console.WriteLine(result);
}
catch (Exception ex)
{
Console.WriteLine(ex.ToString());
}
如果问题仍然存在,请随时告诉我。
推荐阅读
- c# - 在页面上显示内容两次,但只定义一次内容
- javascript - 使用jquery获取总价
- python-3.6 - 从 py2 转移到 py3 时的导入问题
- python - 你能发现这个 REGEX 语句的问题吗?
- laravel - 视图中的 laravel 帖子不调用控制器方法
- c# - EF Core 2.2 LoggerFactory 未将 DB 命令记录到控制台
- c - 有没有办法可以在 if 语句中输入“但是”?
- php - 如何从 woocommerce 电子邮件中删除价格列?
- android - 为什么 Android 不使用最新的 gradle 版本?
- python - aiohttp、asyncio 和 RuntimeError:会话已关闭