httpRequest -> getURL -> NAV/NAS Download From the internet
g00fy
Member Posts: 2
I need to write a function in a CU, that will download data from given url and hopefully give me info about downloading time. This function is used in CU that runs on NAS (shelude). The function should return True if everything went OK, and False if there were any problems.
My Probelm:
1. Everything works fine, unless there is a "networking problem".
2. When there is a "networking problem" (example, unplugged ETH cable), then Automation variables, will throw Exceptions that I can't handle in Navision (or can I?)
3. When using XMLHTTP40 I can't download files when varAsync=True (don't know why), and I can download files when varAsync=FALSE, but when there is a "networking problem" it starts to throw exceptions.
Does Any 1 know what to do here?
I know that http://www.mibuso.com/dlinfo.asp?FileID=952 works, but this works only when varAsync=TRUE & the "checking of the status" is done on OnTimer trigger. Also the embeded function in the form (where varAsync=False) has the same issues as my functions.
Function nr. 1 (AFAIK this works better, but when varAsync=TRUE, I can't get anything)
Function nr. 2 -> This works OK when there are no networking problems, when there are, it throws exceptions.
Running NAV2009R2.
Does any 1 have working implementation (even without elapsed time, but with timeout limit) of something similar?
My Probelm:
1. Everything works fine, unless there is a "networking problem".
2. When there is a "networking problem" (example, unplugged ETH cable), then Automation variables, will throw Exceptions that I can't handle in Navision (or can I?)
3. When using XMLHTTP40 I can't download files when varAsync=True (don't know why), and I can download files when varAsync=FALSE, but when there is a "networking problem" it starts to throw exceptions.
Does Any 1 know what to do here?
I know that http://www.mibuso.com/dlinfo.asp?FileID=952 works, but this works only when varAsync=TRUE & the "checking of the status" is done on OnTimer trigger. Also the embeded function in the form (where varAsync=False) has the same issues as my functions.
Function nr. 1 (AFAIK this works better, but when varAsync=TRUE, I can't get anything)
PROCEDURE GetURL@1000000001(VAR response@1000000007 : BigText;url@1000000009 : Text[1024];VAR timeout@1000000001 : Integer) : Boolean;
VAR
httpRequest@1000000002 : Automation "{F5078F18-C551-11D3-89B9-0000F81FE221} 6.0:{F6D90F16-9C73-11D3-B32E-00C04F990BB4}:'Microsoft XML, v6.0'.XMLHTTP";
WinHttpRequest@1000000003 : Automation "{662901FC-6951-4854-9EB2-D9A2570F2B2E} 5.1:{2087C2F4-2CEF-4953-A8AB-66779B670495}:'Microsoft WinHTTP Services, version 5.1'.WinHttpRequest";
elapsed@1000000005 : Integer;
TimeBegin@1000000006 : Time;
IStream@1000000010 : InStream;
BEGIN
CREATE(httpRequest);
httpRequest.open('GET',url,TRUE);
// True - Does not work ?
// False - Works only when ETH connection is UP
TimeBegin:=TIME;
httpRequest.send();
COMMIT;
REPEAT
BEGIN
elapsed:=TIME-TimeBegin;
IF (elapsed>=timeout) THEN
BEGIN
CLEAR(httpRequest);
EXIT(FALSE)
END;
END;
UNTIL ((httpRequest.readyState() = 4));
IF NOT (httpRequest.status = 200) THEN
BEGIN
CLEAR(httpRequest);
EXIT(FALSE);
END;
IStream:= httpRequest.responseStream();
CLEAR(httpRequest);
CLEAR(response);
response.READ(IStream);
timeout:=timeout-elapsed;
EXIT(TRUE);
END;
Function nr. 2 -> This works OK when there are no networking problems, when there are, it throws exceptions.
PROCEDURE GetURL@1000000001(VAR response@1000000007 : BigText;url@1000000009 : Text[1024];VAR timeout@1000000001 : Integer) : Boolean;
VAR
httpRequest@1000000002 : Automation "{F5078F18-C551-11D3-89B9-0000F81FE221} 6.0:{F6D90F16-9C73-11D3-B32E-00C04F990BB4}:'Microsoft XML, v6.0'.XMLHTTP";
WinHttpRequest@1000000003 : Automation "{662901FC-6951-4854-9EB2-D9A2570F2B2E} 5.1:{2087C2F4-2CEF-4953-A8AB-66779B670495}:'Microsoft WinHTTP Services, version 5.1'.WinHttpRequest";
elapsed@1000000005 : Integer;
TimeBegin@1000000006 : Time;
IStream@1000000010 : InStream;
BEGIN
CREATE(WinHttpRequest);
WinHttpRequest.Open('GET',url,TRUE);
TimeBegin:=TIME;
WinHttpRequest.Send;
IF NOT WinHttpRequest.WaitForResponse(timeout) THEN
EXIT(FALSE);
timeout:=TIME-TimeBegin;
IF NOT (WinHttpRequest.Status =200) THEN
EXIT(FALSE);
IStream := WinHttpRequest.ResponseStream;
response.READ(IStream);
CLEAR(IStream);
CLEAR(WinHttpRequest);
EXIT(TRUE);
END;
Running NAV2009R2.
Does any 1 have working implementation (even without elapsed time, but with timeout limit) of something similar?
0
Comments
-
Hello, i also faced to that problem, I've solved it writing a simple codeunit Test HTTP Connection:
OnRun()
CRMSetupL.GET;
CREATE(HTTPL);
HTTPL.open('GET', CRMSetupL."Bonus Server Url", FALSE);
HTTPL.send('<hello></hello>');
IF HTTPL.status <> 200 THEN;
So, before getting some url I check the connection:
SendRequest()
IF NOT TestHTTPConnection.RUN() THEN ERROR(ConnectionFailed);
Detail information in my article: http://x-dynamics.blogspot.com/2011/06/interaction-with-web-service-from-nav.html
Hope this helps!Sincerely yours, GRIZZLY
Follow my blog at http://x-dynamics.blogspot.com0 -
Categories
- All Categories
- 73 General
- 73 Announcements
- 66.7K Microsoft Dynamics NAV
- 18.8K NAV Three Tier
- 38.4K NAV/Navision Classic Client
- 3.6K Navision Attain
- 2.4K Navision Financials
- 116 Navision DOS
- 851 Navision e-Commerce
- 1K NAV Tips & Tricks
- 772 NAV Dutch speaking only
- 617 NAV Courses, Exams & Certification
- 2K Microsoft Dynamics-Other
- 1.5K Dynamics AX
- 328 Dynamics CRM
- 111 Dynamics GP
- 10 Dynamics SL
- 1.5K Other
- 990 SQL General
- 383 SQL Performance
- 34 SQL Tips & Tricks
- 35 Design Patterns (General & Best Practices)
- 1 Architectural Patterns
- 10 Design Patterns
- 5 Implementation Patterns
- 53 3rd Party Products, Services & Events
- 1.6K General
- 1.1K General Chat
- 1.6K Website
- 83 Testing
- 1.2K Download section
- 23 How Tos section
- 252 Feedback
- 12 NAV TechDays 2013 Sessions
- 13 NAV TechDays 2012 Sessions