首页 > 解决方案 > 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 服务。

标签: 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());
        }

如果问题仍然存在,请随时告诉我。


推荐阅读