• wcf 之旅ERROR安全模式Transport传输安全 (未能为 SSL/TLS 安全通道建立信任的解决办法)


     ----------------------源代码

    static void Main()
            {
                  // WARNING: This code is only needed for test certificates such as those created by makecert. It is
                // not recommended for production code.
                  PermissiveCertificatePolicy.Enact("CN = WIN-85QBE2LGCIQ");

                // Create a client with given client endpoint configuration
                CalculatorClient client = new CalculatorClient();

                // Call the Add service operation.
                double value1 = 100.00D;
                double value2 = 15.99D;
                double result = client.Add(value1, value2);        //执行到这里会报异常:未能为 SSL/TLS 安全通道建立信任
                Console.WriteLine("Add({0},{1}) = {2}", value1, value2, result);

    -------------------------修改后代码

       private static bool ValidateServerCertificate(object sender, X509Certificate certificate, X509Chain chain,SslPolicyErrors sslPolicyErrors)
            {
                return true;
            }

      static void Main()
            {
                ServicePointManager.ServerCertificateValidationCallback = ValidateServerCertificate;
                      // WARNING: This code is only needed for test certificates such as those created by makecert. It is
                // not recommended for production code.
                //  PermissiveCertificatePolicy.Enact("CN = WIN-85QBE2LGCIQ");

                // Create a client with given client endpoint configuration
                CalculatorClient client = new CalculatorClient();

                // Call the Add service operation.
                double value1 = 100.00D;
                double value2 = 15.99D;
                double result = client.Add(value1, value2);
                Console.WriteLine("Add({0},{1}) = {2}", value1, value2, result);

    ....

           }

  • 相关阅读:
    mysql 格林威治时间
    设置Highcharts刻度间距
    在PHP中判断单个字符是不是中文字符
    将ip以整形数据存储在数据库中的相关操作
    【Demo 0016】Windows 基本数据结构
    【Demo 0019】编码转换
    【Demo 0018】文字编码
    【Demo 0014】图形对象路径
    【Demo 0010】绘图对象区域
    【Demo 0017】Win32 基本结构体(1)
  • 原文地址:https://www.cnblogs.com/520cc/p/3092355.html
Copyright © 2020-2023  润新知