WCF服务用错误消息发出错误消息,无法使用权​​限建立SSL / TLS的安全通道

时间:2018-11-28 00:53:39

标签: wcf

您好,我正在尝试调用网络服务:-

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服务并不难。

2 个答案:

答案 0 :(得分:0)

如果您查看Microsoft Documentation,他们将通过以下示例显示如何将basichttpbinding连接到SSL

   <system.serviceModel>  
       <services>  
          <service   
              type="Microsoft.ServiceModel.Samples.CalculatorService"  
              behaviorConfiguration="CalculatorServiceBehavior">  
             <endpoint address=""  
                   binding="basicHttpBinding"  
                   bindingConfiguration="Binding1"   
                   contract="Microsoft.ServiceModel.Samples.ICalculator" />  
          </service>  
       </services>  
        <bindings>  
            <basicHttpBinding>  
            <!-- Configure basicHttpBinding with Transport security -- >  
            <!-- mode and clientCredentialType set to None.-->  
               <binding name="Binding1">  
                   <security mode="Transport">  
                       <transport clientCredentialType="None"  
                                  proxyCredentialType="None">  
                           <extendedProtectionPolicy  
                              policyEnforcement="WhenSupported"  
                              protectionScenario="TransportSelected">  
                        <customServiceNames></customServiceNames>  
                           </extendedProtectionPolicy>  
                   </security>  
               </binding>  
            </basicHttpBinding>  
        </bindings>  
    </system.serviceModel> 

答案 1 :(得分:0)

在通过添加服务引用来调用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());
        }

请随时让我知道问题是否仍然存在。