web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics AX (Archived)

Reading XML with HTTPS

(0) ShareShare
ReportReport
Posted on by 52

Hello Community,

We have an issue reading XML coming with SSL Certificate, with https URL. Example of the URL is like this : https://site.com/page.php?key=xxx&date=2018-07-15

This URL shows a page with XML structure. I can read and save it to table, if it comes with http and no ssl certificate. But when it comes with ssl https, it gives an exception like below:

System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.Net.WebException: The request was aborted: Could not create SSL/TLS secure channel.
at System.Net.HttpWebRequest.GetResponse()
--- End of inner exception stack trace ---
at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor)
at System.Reflection.RuntimeMethodInfo.UnsafeInvokeInternal(Object obj, Object[] parameters, Object[] arguments)
at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
at Microsoft.Dynamics.AX.ManagedInterop.ClrBridgeImpl.InvokeClrInstanceMethod(ClrBridgeImpl* , ObjectWrapper* objectWrapper, Char* pszMethodName, Int32 argsLength, ObjectWrapper** arguments, Boolean* argsAreByRef, Boolean* isException)

I read it with following code:

 System.Net.WebResponse              webResponse;
    System.Net.HttpWebRequest           httpWebRequest;
    System.Net.WebHeaderCollection      webHeaderCollection;
    System.IO.StreamReader              streamReader;
    System.IO.Stream                    stream;
    System.Exception                    netExcepn;
    str                                 xmlOut;
    XmlDocument                         xmlDocument;
    XmlNodeList                         xmlNodeList;
    XmlNode                             mainNode;
    XmlNode                             childNode;
    
    
    #define.ServiceTimeout(5000)
    #define.ServiceURL(xmlAddress)
    #define.mainNodeName('orders')
    #define.childNodeName('order')



    #define.HttpWebRequestMethod("GET")
    #define.HttpWebRequestContentType("application/xml")
    #define.HttpHeaderAuthorization("Authorization")


    if(this.validateURL(xmlAddress))
    {
        try
        {
        httpWebRequest          = System.Net.WebRequest::CreateHttp(#ServiceURL);
        httpWebRequest.set_Method(#HttpWebRequestMethod);
        httpWebRequest.set_ContentType(#HttpWebRequestContentType);
        httpWebRequest.set_Timeout(#ServiceTimeout);
        //httpWebRequest.set_ClientCertificates(
        webHeaderCollection     = httpWebRequest.get_Headers();
        webResponse             = httpWebRequest.GetResponse();
        stream                  = webResponse.GetResponseStream();
        streamReader            = new System.IO.StreamReader(stream);
        info("@QQL940");
        }
        catch(Exception::CLRError)
        {
            netExcepn = CLRInterop::getLastException();
            info(netExcepn.ToString());
        }
    }
    else
    {
        streamReader            = new System.IO.StreamReader(xmlAddress);
        info("@QQL941");
    }

    if(!sourceId)
    {
        checkFailed("@QQL946");
        return;
    }
    xmlOut                  = streamReader.ReadToEnd();


    xmlDocument             = XmlDocument::newXml(XMLOut);
    mainNode                = xmlDocument.selectSingleNode(#mainNodeName);
    xmlNodeList             = mainNode.selectNodes(#childNodeName);
    childNode               = xmlNodeList.nextNode();

    while (childNode)
    {
        this.parseXML(childNode);
        childNode               = xmlNodeList.nextNode();
    }

    info("@QQL942");
   // --------------------- READ FROM XML-----------------
}


Can you please help me to solve this problem.

Thanks in advance.

*This post is locked for comments

I have the same question (0)
  • Suggested answer
    Mea_ Profile Picture
    60,284 on at

    Hi badiyev,

    Try to add this line before httpWebRequest = System.Net.WebRequest::CreateHttp(#ServiceURL)

    System.Net.ServicePointManager::set_SecurityProtocol(System.Net.SecurityProtocolType::Ssl3);
  • badiyev Profile Picture
    52 on at

    ievgen, thanks for your response, but this did not solve my problem :(

  • Verified answer
    Mea_ Profile Picture
    60,284 on at

    You may try SecurityProtocolType::Tls12 or SecurityProtocolType::Tls or  SecurityProtocolType::Tls11 as well because It's obviously hard for me to tell what your web service expecting and what .Net version it is.

  • badiyev Profile Picture
    52 on at

    That did the trick for me, also, i have defined the certificate and showed the path to certificate in order Ax to understand which certificate should it use.

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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics AX (Archived)

#1
Martin Dráb Profile Picture

Martin Dráb 4 Most Valuable Professional

#1
Priya_K Profile Picture

Priya_K 4

#3
MyDynamicsNAV Profile Picture

MyDynamicsNAV 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans