Automation to .NET - XMLHttpConn Component

martinhocosta88martinhocosta88 Member Posts: 27
edited 2015-05-26 in NAV Three Tier
Hello,

A partner is trying to post an invoice via web service and is getting an error because of an automation component: XMLHttpConn in a specific codeunit. I'm wondering about remaking it's implementation in .NET since it could solve this problem and the webclient limitations over automation also.
I thought about System.Xml.XmlDocument but the problem is occurring in the following code:

IF ISCLEAR(XMLHttpConn) THEN
CREATE(XMLHttpConn,TRUE,TRUE);

So I would like to know if anyone know a .net component that could replace XMLHttpConn in the connection scope.

thanks in advance.

Comments

  • NixPtNixPt Member Posts: 19
    Boas espero que ajude, Hope this helps

    Name	DataType	Subtype	Length
    XmlHttpRequest_DotNet	DotNet	'System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.System.Net.HttpWebRequest	
    XmlHttpResponse_DotNet	DotNet	'System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.System.Net.HttpWebResponse	
    XmlDomElem_Dotnet	DotNet	'System.Xml, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.System.Xml.XmlElement	
    xmlProcessingInst	DotNet	'System.Xml, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.System.Xml.XmlProcessingInstruction	
    
    NewChild	DotNet	'System.Xml, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.System.Xml.XmlNode	
    CurrNode1	DotNet	'System.Xml, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.System.Xml.XmlNode	
    CurrNode2	DotNet	'System.Xml, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.System.Xml.XmlNode	
    CurrNode3	DotNet	'System.Xml, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.System.Xml.XmlNode	
    CurrNode4	DotNet	'System.Xml, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.System.Xml.XmlNode	
    ______	Integer		
    MemoryStream	DotNet	'mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.System.IO.MemoryStream	
    Encoding	DotNet	'mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.System.Text.Encoding	
    Bytes	DotNet	'mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.System.Array	
    TempBlob	Record	TempBlob	
    vInStream	InStream		
    vBigText	BigText		
    vOutStream	OutStream
    
    ///////////////////////////
    //Creates SOAP Connection//
    ///////////////////////////
    
    XmlHttpRequest_DotNet := XmlHttpRequest_DotNet.Create('https://onlinetools.ups.com/webservices/TimeInTransit');
    XmlHttpRequest_DotNet.ContentType('application/xml;charset=utf-8');
    XmlHttpRequest_DotNet.KeepAlive(TRUE);
    XmlHttpRequest_DotNet.Method('POST');
    XmlHttpRequest_DotNet.ReadWriteTimeout(5000);
    XmlHttpRequest_DotNet.Timeout(5000);
    
    ///STREAM REQUEST///
    TempBlob.Blob.CREATEOUTSTREAM(vOutStream);
    XmlDomDoc_DotNet.Save(vOutStream);
    
    CLEAR(INSTREAM);
    MemoryStream := MemoryStream.MemoryStream();
    TempBlob.Blob.CREATEINSTREAM(vInStream);
    vBigText.READ(vInStream);
    
    
    Bytes := Encoding.UTF8.GetBytes(vBigText);
    XmlHttpRequest_DotNet.ContentLength(Bytes.Length);
    
    MemoryStream := XmlHttpRequest_DotNet.GetRequestStream;
    MemoryStream.Write(Bytes,0,Bytes.Length);
    MemoryStream.Close;
    MemoryStream.Dispose;
    
    //Get Response
    
    XmlHttpResponse_DotNet := XmlHttpRequest_DotNet.GetResponse;
    XmlDomDoc_DotNet.Load(XmlHttpResponse_DotNet.GetResponseStream);
    XmlHttpResponse_DotNet.Close;
    
    
    XmlDomNoneList_DotNet := XmlDomDoc_DotNet.GetElementsByTagName('common:Code');
    XmlDomNode_DotNet := XmlDomNoneList_DotNet.Item(0);
    
    XmlDomDoc_DotNet.Save('C:\UPS_LeadTimes_Response.xml');
    
  • Dan_KDan_K Member Posts: 3
    Hello,

    A partner is trying to post an invoice via web service and is getting an error because of an automation component: XMLHttpConn in a specific codeunit. I'm wondering about remaking it's implementation in .NET since it could solve this problem and the webclient limitations over automation also.
    I thought about System.Xml.XmlDocument but the problem is occurring in the following code:

    IF ISCLEAR(XMLHttpConn) THEN
    CREATE(XMLHttpConn,TRUE,TRUE);

    So I would like to know if anyone know a .net component that could replace XMLHttpConn in the connection scope.

    thanks in advance.

    Yes you can pretty much directly replace the automations using .NET. We were using MSXML03 in our Classic product and have rewritten everthing in DotNet using the System.Xml library.

    If you're using DotNet variables you'll need to initialise the variable slightly differently.

    For XMLDocument you can use the constructor e.g;

    XMLDoc := XMLDoc.XmlDocument();

    You can check to see if the DotNet variable has been initialised using ISNULL.

    e.g. IF ISNULL(XMLDoc) THEN...

    Have a look at System.Net.HttpWebRequest for your XMLHttpConn variable.
  • martinhocosta88martinhocosta88 Member Posts: 27
    Thank you both. That actually helped
Sign In or Register to comment.