Problem with BigText and OCX "Microsoft Internet Transfer Control 6.0"

Hello!

We are trying to retrieve some information from a webservice in our Navision 5 system. Therefore, we use the OCX "Microsoft Internet Transfer Control 6.0" and do a GET request from a URL.

As an answer, we receive a string of text. This text can be bigger then 1024 digits - so we can not work with a normal text variable when assigning the return value like this:

Result:= MIT.OpenURL(ServiceURL);

Due to that, we want to use the type BigText, which should be big enough. The problem is, that it doesnt work - the text is not assigned. When we assign it like this:

Result.ADDTEXT(MIT.OpenURL(ServiceURL));

and afterwards check the length of the variable, it is always 0.

MESSAGE(FORMAT(Result.LENGTH));

Is there any difference regarding what values can be assigned? Or do you think of any other possiblity? I already tried writing the result directly into a text file - this can also only be 1024 digits at a time. I also wasn't able to do it with a blob field..

If you know what I did wrong, or have any idea how to handle it otherwise, I would be happy for any help.

Thanks for any input,
kola1

Best Answer

  • Slawek_GuzekSlawek_Guzek Member Posts: 1,690
    Answer ✓
    I don't think that Result.ADDTEXT(MIT.OpenURL(ServiceURL)) will let you overcome the 1024 length limit. The reason is that NAV will execute 2 separate commands - try runnig it in debugger and you will have to press F8 twice to pass the line. In between commands the output of MIT.OpenURL() must be stored somewhere before passing it to ADDTEXT - and I guess that would be in some undeclared internal variable.

    I guess very the same reason caused the 'direct' write to a file to be limited to 1024 characters.

    You need to find a method to pass a file name or a stream to the OCX component, and make the component to write directly to the stream or a file - without passing the data through NAV.

    Any code structure like Result.ADDTEXT(MIT.OpenURL(ServiceURL)) constitutes passing the data through NAV. Any construct like this will be subject to maximum NAV text limit.

    If your OCX doesn't have any methods where you can pass the file name (or a stream) as a destination of OpenURL you may be forced to use some different component. I believe you may be able to find examples here on mibuso of using some automation components to handle http requests

    Slawek

    Slawek Guzek
    Dynamics NAV, MS SQL Server, Wherescape RED;
    PRINCE2 Practitioner - License GR657010572SG
    GDPR Certified Data Protection Officer - PECB License DPCDPO1025070-2018-03

Answers

  • Slawek_GuzekSlawek_Guzek Member Posts: 1,690
    Answer ✓
    I don't think that Result.ADDTEXT(MIT.OpenURL(ServiceURL)) will let you overcome the 1024 length limit. The reason is that NAV will execute 2 separate commands - try runnig it in debugger and you will have to press F8 twice to pass the line. In between commands the output of MIT.OpenURL() must be stored somewhere before passing it to ADDTEXT - and I guess that would be in some undeclared internal variable.

    I guess very the same reason caused the 'direct' write to a file to be limited to 1024 characters.

    You need to find a method to pass a file name or a stream to the OCX component, and make the component to write directly to the stream or a file - without passing the data through NAV.

    Any code structure like Result.ADDTEXT(MIT.OpenURL(ServiceURL)) constitutes passing the data through NAV. Any construct like this will be subject to maximum NAV text limit.

    If your OCX doesn't have any methods where you can pass the file name (or a stream) as a destination of OpenURL you may be forced to use some different component. I believe you may be able to find examples here on mibuso of using some automation components to handle http requests

    Slawek

    Slawek Guzek
    Dynamics NAV, MS SQL Server, Wherescape RED;
    PRINCE2 Practitioner - License GR657010572SG
    GDPR Certified Data Protection Officer - PECB License DPCDPO1025070-2018-03
  • ErictPErictP Member Posts: 164
    edited 2017-08-22
    Maybe you can try this with the automation object XMLHTTP60
    OBJECT Codeunit 70000 ReadWebservice
    {
      OBJECT-PROPERTIES
      {
        Date=22-08-17;
        Time=15:10:46;
        Modified=Yes;
        Version List=;
      }
      PROPERTIES
      {
        OnRun=BEGIN
                CallWebservice;
              END;
    
      }
      CODE
      {
    
        PROCEDURE CallWebservice@1000002() : Text[30];
        VAR
          autXmlHttp@1000016 : Automation "{F5078F18-C551-11D3-89B9-0000F81FE221} 6.0:{88D96A0A-F192-11D4-A65F-0040963251E5}:'Microsoft XML, v6.0'.XMLHTTP60";
          TempBlob@1000001 : TEMPORARY Record 99008535;
          TempInstream@1000002 : InStream;
          L_Txt@1000005 : Text[1024];
          ServiceURL@1000000000 : Text[1024];
        BEGIN
          CLEAR(TempBlob);
          CLEAR(TempInstream);
          CLEAR(autXmlHttp);
          CREATE(autXmlHttp);
    
          ServiceURL := 'https://webserviceURL';
          autXmlHttp.open('GET', ServiceURL,0);
          autXmlHttp.setRequestHeader('Content-type','text/xml');
          autXmlHttp.send();
    
          TempBlob.Blob.CREATEINSTREAM(TempInstream);
          TempInstream := autXmlHttp.responseStream;
    
          WHILE NOT (TempInstream.EOS()) DO
            BEGIN
              TempInstream.READTEXT(L_Txt);
              //Do want you want with l_Txt
            END;
        END;
    
        BEGIN
        END.
      }
    }
    
    
    
Sign In or Register to comment.