Skip to main content

Notifications

Community site session details

Community site session details

Session Id :
Finance | Project Operations, Human Resources, ...
Unanswered

How can use Tls 1.2 in Ax 2009

(0) ShareShare
ReportReport
Posted on by 5

Hi, 

I'm reading xml from URL and using that xml. But The URL started using TLS 1.2 so my code is not running.

TLS 1.2 has been added in server (i see it in regedit protocols)

My old code is below. I used webclient but OpenRead method no works. I hope use HttpClient but i dont know use that.

FreeTxt EDMReadXML(name _Url)
{
System.Net.WebClient webClient;
System.IO.Stream stream;
System.IO.StreamReader streamReader;
System.String line;
Notes rXML;
;

new InteropPermission(InteropKind::ClrInterop).assert();

webClient = new System.Net.WebClient();
stream = webClient.OpenRead(_Url);
streamReader = new System.IO.StreamReader(stream);


line = streamReader.ReadLine();

rXML = streamReader.ReadToEnd();

while(!System.String::IsNullOrEmpty(line))
{
line = streamReader.ReadLine();
}

streamReader.Close();
streamReader.Dispose();
stream.Close();
stream.Dispose();

return rXML;

}

Can you help me pls??

  • SantaKlaus Profile Picture
    2 on at
    How can use Tls 1.2 in Ax 2009
    Hi!
     
    vv1984, its's work!
     
    1) Windows has forcibly enabled the use of TLS 1.2 only.
    2) NET Framework version 4.5 must be installed
    3) And all of the 2 and 3 your points.
     
     
    static void tutor_RESTAPI(Args _args)
    {
        str                             url;
        str                             postData;
        str                             returnValue;
        str                             errorMessage;
        System.Uri                      uri;
        System.Net.HttpWebRequest       request;
        System.Net.HttpWebResponse      response;
        System.Net.WebException         webException;
        System.Exception                systemCLRException;
        System.Byte[]                   byteArray;
        System.IO.Stream                dataStream;
        System.IO.StreamReader          streamReader;
        System.Net.ServicePoint         servicePoint;
        System.Net.ServicePointManager  servicePointManager;
        System.Net.WebHeaderCollection  webHeaderCollection;
        CLRObject                       clrObj;
        System.Text.Encoding            textEncoding = System.Text.Encoding::get_UTF8();
        int                             httpStatusCode;
        ;
        new InteropPermission(InteropKind::ClrInterop).assert();
        System.Net.ServicePointManager::set_SecurityProtocol(System.Net.SecurityProtocolType::Tls12);
        try
        {
            url     = "http://ya.ru";
            uri     = new System.Uri(url);
            clrObj  = System.Net.WebRequest::Create(uri);
            request = clrObj;
            request.set_KeepAlive(False);
            request.set_Method("GET");
            request.set_ContentType("application/json");
            request.set_Accept("application/json");
            response = request.GetResponse();
            dataStream = response.GetResponseStream();
            streamReader = new System.IO.StreamReader(dataStream);//, textEncoding);
            returnValue = streamReader.ReadToEnd();
            httpStatusCode = response.get_StatusCode();
            info(returnvalue);
        }
        catch (Exception::CLRError)
        {
            if (xSession::currentRetryCount() >= 2)
            {
                CodeAccessPermission::revertAssert();
                new InteropPermission(InteropKind::ClrInterop).assert();
                webException        = CLRInterop::getLastException();
                systemCLRException  = CLRInterop::getLastException();
                while (!CLRInterop::isNull(webException))
                {
                    errorMessage += webException.get_Message();
                    webException = webException.get_InnerException();
                }
                while (!CLRInterop::isNull(systemCLRException))
                {
                    errorMessage += systemCLRException.get_Message();
                    systemCLRException = systemCLRException.get_InnerException();
                }
                CodeAccessPermission::revertAssert();
                error(errorMessage);
            }
            else
            {
                retry;
            }
        }
        catch
        {
            warning("An error occurred while executing the request");
        }
        if (response)
        {
            streamReader.Close();
            dataStream.Close();
            response.Close();
        }
        CodeAccessPermission::revertAssert();
    }
  • vv1984 Profile Picture
    1,087 on at
    RE: How can use Tls 1.2 in Ax 2009

    Hi,

    my answer will surely be not complete since I'm struggling as well on this issue.

    I've seen different approaches to this:

    1. To force the usage of TLS 1.2 instead of older versions of the protocol (which seems the way you tried). I've tried it but doesn't seems to work. Perhaps your situation may be different, have you tried to explicity disable the other ones (e.g SSL 2.0 and TLS 1.1)?

    2. To specify Ax to use NET Framework version 4.5 (since TLS 1.2 is only supported from 4.5 and above). This should be achieved by adding file ax32.exe.config in folder C:\Program Files (x86)\Microsoft Dynamics AX\50\Client\Bin of your terminal server and the same file in the folder C:\Program Files\Microsoft Dynamics AX\50\Server\[my aos instance name]\Bin of the AOS machine.

    This file should contain the following

    <?xml version="1.0" encoding="utf-8" ?>

    <configuration>

     <startup useLegacyV2RuntimeActivationPolicy="true">

          <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5"/>

     </startup>

    </configuration>

    3. To cast the type of the SecurityProtocolType enum in order to force TLS1.2 value. See this link for reference (is in russian, but can be understood pretty well using automatic translation) axforum.info/.../showthread.php

    4. To create a separate .NET 4.5 process (see Martin's last reply). Unfortunately I don't have necessary knowledge to find a way to do this and steps to be taken are not specified in this thread...

    www.dynamicsuser.net/.../64961

    Needless to say I've tried them all but none of them worked for me. Let's keep in touch in case any of us finds a solution.

    Thanks

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

🌸 Community Spring Festival 2025 Challenge 🌸

WIN Power Platform Community Conference 2025 tickets!

Jonas ”Jones” Melgaard – Community Spotlight

We are honored to recognize Jonas "Jones" Melgaard as our April 2025…

Kudos to the March Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 294,165 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 232,968 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,158 Moderator

Leaderboard

Product updates

Dynamics 365 release plans