Transfer file from Navision to website

MHols
Member Posts: 2
Greetings,
I am looking for a way to send a file with a Navision CodeUnit to a website (preferably a custom WebService). After searching through these great forums I found many posts explaining how to contact a WebService from Nav to send ordinary data, however the files I wish to transfer usually are images (.GIF, .JPG, .PNG), compressed archives (.RAR, .ZIP), documents (.PDF, .DOC(X)), spreadsheets (.XLS(X)), etc. of up to 8MB each. I am a fair C# programmer but my Navision knowledge is quite limited.
Here is my situation as short as possible:
1. Someone makes a support-call in Navision and adds attachments to it on their own server (the attachments are saved on their own network drive, the path to the file is stored in Nav).
2. A call can then be transfered to our WebService (which was created in C#) and the call is duplicated within our own Navision database.
3. After the call was created I wish to send their attachments to our webservices too, but I require some assistance with getting this part right.
After searching the forums I found this post ("Re: how to put a jpg file into a xml file by xmlport ?") and after a few minutes of trying to understand this code, I figured it gets me into the right direction but it is incomplete (some declarations such as Trans & URItemp are missing, the namespace SOAP does not appear to be defined, etc.) and I really can't figure out the purpose of some of the functions. Where does Convert2binary do it's encoding? How does the receiving WebService look like? What does the second parameter of SendSOAP(URL,URItemp+Action,GetResult) ; do?
Well anyway, disregarding the above example, what method would be best to transfer one or more file(s) accessible from within Navision (smaller than 8MB) to our website, and how to do that within Navision? Is there a different (better) method then WebServices?
Does anyone have a working CodeUnit they are willing to share?
or
How to a) open a file, b) encode it with base64 and then c) send it to a WebService? (I basically know the answer to c.)
Thanks in advance for all your help.
Edit:
We all use Classic 2009 clients, so ADDTEXT as suggested in this post won't work.
I am looking for a way to send a file with a Navision CodeUnit to a website (preferably a custom WebService). After searching through these great forums I found many posts explaining how to contact a WebService from Nav to send ordinary data, however the files I wish to transfer usually are images (.GIF, .JPG, .PNG), compressed archives (.RAR, .ZIP), documents (.PDF, .DOC(X)), spreadsheets (.XLS(X)), etc. of up to 8MB each. I am a fair C# programmer but my Navision knowledge is quite limited.
Here is my situation as short as possible:
1. Someone makes a support-call in Navision and adds attachments to it on their own server (the attachments are saved on their own network drive, the path to the file is stored in Nav).
2. A call can then be transfered to our WebService (which was created in C#) and the call is duplicated within our own Navision database.
3. After the call was created I wish to send their attachments to our webservices too, but I require some assistance with getting this part right.
After searching the forums I found this post ("Re: how to put a jpg file into a xml file by xmlport ?") and after a few minutes of trying to understand this code, I figured it gets me into the right direction but it is incomplete (some declarations such as Trans & URItemp are missing, the namespace SOAP does not appear to be defined, etc.) and I really can't figure out the purpose of some of the functions. Where does Convert2binary do it's encoding? How does the receiving WebService look like? What does the second parameter of SendSOAP(URL,URItemp+Action,GetResult) ; do?
Well anyway, disregarding the above example, what method would be best to transfer one or more file(s) accessible from within Navision (smaller than 8MB) to our website, and how to do that within Navision? Is there a different (better) method then WebServices?
Does anyone have a working CodeUnit they are willing to share?
or
How to a) open a file, b) encode it with base64 and then c) send it to a WebService? (I basically know the answer to c.)
Thanks in advance for all your help.
Edit:
We all use Classic 2009 clients, so ADDTEXT as suggested in this post won't work.
0
Comments
-
Base64 encoding; you can do it in NAV, but it's very slow.
Best bet would be some sort of custom automation object that opens the file and returns the encoded file to NAV. Maybe line by line, maybe already as a DOMDocument. In fact in your shoes I would probably just pass the filename to send to a custom C# automation object and get it to do the lot.
Base64 in NAV ... :shock:CountChar Integer StrBuf Text64 Base64Char Text64 b Text3 c Char nWritten Integer
{ On entry Str contains the string to be converted to base64. MaxSz is the maximum number of base64 characters the function will put into the return string, it must be four or more. The number of characters actually returned will be a multiple of four. On exit Str will have upto 2 characters left in it that are unconverted. This is so long strings can be converted in parts. At the end of the strings you must call the routine with the leftover piece and and the last 4 characters of the base64 will be generated (with '=' characters as needed). If MaxSz is zero the entire input string is converted even if it's not a multiple of 3 long. } IF Str = '' THEN EXIT(''); Base64Char := 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'; IF MaxSz > MAXSTRLEN(Bstr) THEN MaxSz := MAXSTRLEN(Bstr); REPEAT b := COPYSTR(Str, 1, 3); Str := COPYSTR(Str, 4); CountChar := STRLEN(b); IF CountChar < 3 THEN BEGIN b[3] := 0; IF CountChar < 2 THEN b[2] := 0; END; c[1] := b[1] DIV 4; // c[1] is high 6 bits of b[1]... c[2] := ((b[1] MOD 4) * 16) + (b[2] DIV 16); // c[2] is low 2 bits of b[1] and high 4 bits of b[2]... c[3] := ((b[2] MOD 16) * 4) + (b[3] DIV 64); // c[3] is low 4 bits of b[2] and high 2 bits of b[3]... c[4] := b[3] MOD 64; // c[4] is low 6 bits of b[3]... c[1] := Base64Char[c[1] + 1]; // convert c[1..4] to the Base64Encoded char... c[2] := Base64Char[c[2] + 1]; IF CountChar > 1 THEN BEGIN c[3] := Base64Char[c[3] + 1]; IF CountChar > 2 THEN c[4] := Base64Char[c[4] + 1] ELSE c[4] := '='; END ELSE c[3] := '='; Bstr[nWritten+1] := c[1]; Bstr[nWritten+2] := c[2]; Bstr[nWritten+3] := c[3]; Bstr[nWritten+4] := c[4]; nWritten += 4; UNTIL (Str = '') OR ((MaxSz > 0) AND ((nWritten+3 >= MaxSz) OR (STRLEN(Str) < 4)));
Robert de Bath
TVision Technology Ltd0
Categories
- All Categories
- 73 General
- 73 Announcements
- 66.6K Microsoft Dynamics NAV
- 18.7K 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
- 320 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