API request works in Javascript but not C#

Hi. We are trying to make requests to the General Ledger - Transaction distribution (List) endpoint. Using the JavaScript example code provided at the endpoint reference works just fine. Here is our implementation:




Unfortunately, we are unable to make a request using the C# example code provided at the endpoint reference. Here is our implementation of that:




Our implementation is exactly the same as the sample code except that we wrapped it in a try-catch, and we added the "var test = response.StatusCode". However, it still does not work even if we leave those out. Here are the error details that we get:




In case that is too small to read, the innerException is "The underlying connection was closed. An unexpected error occurred on a send."


Does anyone have any ideas as to why this is not working for us? We would rather make these requests on the server rather than the client, so we need to get the C# working.


Thanks in advance for any insight you can share,


Bryce

Comments

  • Hi Bryce,


    Are you setting TLS protocol to something later than 1.0 (which has been deprecated)? If your default on the C# machine is TLS 1.0 then it's likely that your calls will fail.


    In your (static) class type initializer, add this line:

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


    You're also welcome to download our SKYLib•NET SKY API code library and SDK which includes a C# (and VB) demo application with source code which you can use to "sanity check" your own app's code. (SKYLib.NET is free for this purpose, working in rate-limited mode of 1 call/s. You can license it for an annual fee to take you up to the fastest call rate, currently 10 call/s.)


    Let me know if this fixes things for you (or not).


    Cheers,

    Steve Cinquegrana | CEO and Principal Developer | Protégé Solutions

     
  • Steve, you're brilliant! And fast! That was the solution. Thanks for getting back to me so quickly. I really appreciate it. Merry Christmas!
  • And to you, Bryce. Glad you got it working. Steve

    #TLS #SecurityProtocol

Categories