【问题标题】:Dynamics 365 Plugin call External REST API - SSL/TSL could not create channel issueDynamics 365 插件调用外部 REST API - SSL/TLS 无法创建通道问题
【发布时间】:2021-07-27 08:09:58
【问题描述】:

我有一个任务是调用外部 REST API 从第三方应用程序获取数据。

在那,我已经创建了一个 C# 控制台应用程序来尝试这个,它工作正常,我可以通过 REST API 从三十方应用程序获取数据。

以前在 Dynamics Custom workflow\Plugin 中尝试过的相同代码,我在下面遇到错误。请就此提出宝贵的建议。

“System.Net.WebException:请求被中止:无法创建 SSL/TLS 安全通道。”

注意:尝试了以下选项,但没有成功。

ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls |安全协议类型.Tls11 |安全协议类型.Tls12; ServicePointManager.ServerCertificateValidationCallback += new RemoteCertificateValidationCallback(AlwaysGoodCertificate); ServicePointManager.Expect100Continue = true;

谢谢, 瓦桑特

【问题讨论】:

    标签: plugins rest dynamics-365


    【解决方案1】:

    不清楚您是如何从 D365 插件调用外部 API。

     // Call external API
     static async Task<bool> CallExternalAPI(Guid beziehungId)  
         {  
           
           bool status = false;  
           HttpClient apiClient = new HttpClient();  
           apiClient.DefaultRequestHeaders.Accept.Clear();  
           apiClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));  
           string url = @"https://reqres.in/api/users?page=2"; 
           HttpResponseMessage response = await apiClient.GetAsync(url);  
           if (response.IsSuccessStatusCode)  
           {  
             var result = response.Content.ReadAsStringAsync().GetAwaiter().GetResult();  
           }  
           return status;  
         }  
         
    

    如果您对 SSL/TLS 安全通道有问题,您可以使用 WebClient。

    // Could not create SSL/TLS secure channel.
    // Use (SecurityProtocolType)3072
    
     using (WebClient client = new WebClient())
     {
          
         client.Headers.Add(HttpRequestHeader.UserAgent, "AvoidError");
         ServicePointManager.Expect100Continue = true;
         //ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12; 
         ServicePointManager.SecurityProtocol = (SecurityProtocolType)3072;
    
         
         htmlCode = client.DownloadString("MY LINK");
    
         //passing the URL again to function from which to extract the content and compare from above content.
         strNewCompanyCode = client.DownloadString("MY LINK");
     }   
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-04-20
      • 2021-12-13
      • 2014-12-26
      • 2017-02-10
      • 2017-08-22
      • 2016-08-03
      • 2018-06-17
      • 1970-01-01
      相关资源
      最近更新 更多