Products

Solutions

Learn More

Partners

Community

Blog

About

Welcome to the DNN Community Forums, your preferred source of online community support for all things related to DNN.
In order to participate you must be a registered DNNizen

HomeHomeDevelopment and...Development and...Building ExtensionsBuilding ExtensionsModulesModulesHow to Resolve Error when connecting to an API from my Custom Module?How to Resolve Error when connecting to an API from my Custom Module?
Previous
 
Next
New Post
1/27/2019 11:41 AM
 

We are extending the source code of a module that targets .NET Framework version 4.5.  Our intent is to use System.Net.Http.HttpClient to send relevant information to a payment API and obtain the response.  However, our diagnostics have shown the following error:  

Exception in HttpClientHandler#31129591::SendAsync - The underlying connection was closed: An unexpected error occurred on a send..

I understand that .NET Framework 4.5 uses an older Transport Layer Security (TLS) than more modern APIs utilize.  I'm thinking this is a root cause but am unsure whether there's something else amiss.  The code that calls this API is as follows:

HttpClientHandler handler = new HttpClientHandler

            {

                AllowAutoRedirect = true

            };

 

            TransactionResult_ProPay result = new TransactionResult_ProPay();

            using (HttpClient client = new HttpClient(new LoggingHandler(new HttpClientHandler())))

            using (HttpClient client = new HttpClient(handler))

            {

                HttpRequestMessage request = new HttpRequestMessage();

                HttpResponseMessage response = new HttpResponseMessage();

                response.EnsureSuccessStatusCode();

                client.BaseAddress = new Uri("https://xmltestapi.propay.com/ProtectPay/HostedTransactions/");

                ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3 | SecurityProtocolType.Tls12 | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls;

                client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));

                string responseBody;

 

                CreateHostedTransactionRequest transactionRequest = new CreateHostedTransactionRequest();

                CreateHostedTransactionResponse transactionResponse = new CreateHostedTransactionResponse();

                HttpContent content = new StringContent(transactionRequest.ToString());

                try

                {

                    request.Headers.Add("Authorization", credentials);

                    request.Headers.Add("accept", "application/json");

                    request.Method = HttpMethod.Put;

                    response = await client.PutAsync("https://xmltestapi.propay.com/ProtectPay/HostedTransactions/", content);

                    responseBody = await response.Content.ReadAsStringAsync();

                    objEventLog.AddLog("Transaction completed", portalSettings, userId,

                        response.ToString(), EventLogController.EventLogType.ADMIN_ALERT);

                    Console.WriteLine(responseBody);

                }

                catch (HttpRequestException ex)

                {

                    result.Succeeded = false;

                    result.ResultMessage = ex.Message;

                    objEventLog.AddLog("Transaction Request Error", portalSettings, userId,

                        ex.Message,

                        EventLogController.EventLogType.ADMIN_ALERT);

                    Console.WriteLine("\nException Caught!");

                    Console.WriteLine("Message :{0} ", ex.Message);

                }

 

                return response.Content.ToString();

It seems like using System.Net.Http.HttpClient may not be the best fit due to the mismatch in TLS versions.  However, before I embark on another approach (calling the API from a .NET Core web service and sending the responses back to the DNN database), I wanted to obtain input as to whether there are other issues preventing a successful connection.  Thanks much for your help and guidance.

 
Previous
 
Next
HomeHomeDevelopment and...Development and...Building ExtensionsBuilding ExtensionsModulesModulesHow to Resolve Error when connecting to an API from my Custom Module?How to Resolve Error when connecting to an API from my Custom Module?


These Forums are dedicated to discussion of DNN Platform and Evoq Solutions.

For the benefit of the community and to protect the integrity of the ecosystem, please observe the following posting guidelines:

  1. No Advertising. This includes promotion of commercial and non-commercial products or services which are not directly related to DNN.
  2. No vendor trolling / poaching. If someone posts about a vendor issue, allow the vendor or other customers to respond. Any post that looks like trolling / poaching will be removed.
  3. Discussion or promotion of DNN Platform product releases under a different brand name are strictly prohibited.
  4. No Flaming or Trolling.
  5. No Profanity, Racism, or Prejudice.
  6. Site Moderators have the final word on approving / removing a thread or post or comment.
  7. English language posting only, please.

Content Layout

Subscribe to DNN Digest

Subscribe to DNN Digest

DNN Digest is our monthly email newsletter. It highlights news and content from around the DNN ecosystem, such as new modules and themes, messages from leadership, blog posts and notable tweets. Keep your finger on the pulse of the ecosystem by subscribing.  

What is Liquid Content?
Find Out
What is Liquid Content?
Find Out
What is Liquid Content?
Find Out