Quantcast
Channel: Microsoft Dynamics AX Forum - Recent Threads
Viewing all articles
Browse latest Browse all 72043

Reading XML with HTTPS

$
0
0

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.


Viewing all articles
Browse latest Browse all 72043

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>