Undefinable output from WebService

Hi Experts,

From a Web-service I get a return-value, that should be Base64 encoded.
While debugging, I see that it doesn't look like base64, I assume that it is base64 but in ASCII format,
When I look into the logging, I see base 64 data.

If it is ASCII, how do I write that to an IFS-file using the open(::::)
I tried a lot of oFlags and modes and some CCSID's, but can't find the right comination

Current open function:
open(%trim(B64FileName) : O_RDWR + O_CREAT + O_TRUNC + O_CCSID + O_TEXTDATA : S_IRWXU + S_IRWXG + S_IRWXO : 819);
close(fd);
open(%trim(B64FileName):O_RDWR+O_TEXTDATA: S_IRWXU + S_IRWXG + S_IRWXO);


Debug result looks like :
■&àã■■■■■■■■■■■?¦■■■■■■■è`
?ÀÁ■■íËÁ+?>Á■■■&/ÅÁ</`?ÍÈ■
■■■■■&Ê?ÀÍÄÁÊ■■&ÀÃäÊÁ/È?Ê■Î
LVL 17
Theo KouwenhovenApplication ConsultantAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Gary PattersonVP Technology / Senior Consultant Commented:
Green-screen debugger just sees this as binary data, and by default assumes it as encoded in whatever CCSID is associated with your session - in the US for example, it would usually be CCSID 37.

If you want to store the return from a web service that returns a BASE64 encoded result, you need to create an IFS file with an ASCII CCSID (BASE64 only uses a limited subset of ASCII characters - 819 would be fine), or you can create an IFS file with a CCSID of 65535 (binary data - do not translate).

Either way, when you write the string to your IFS file, you need to make sure that no automatic CCSID conversion takes place. This means you should not specify O_TEXTDATA, since this triggers automatic conversion - you want to save this data just as it came back from the web service.

Haven't tested this, but this looks right to me:

open(%trim(B64FileName) : O_RDWR + O_CREAT + O_TRUNC + O_CCSID : S_IRWXU + S_IRWXG + S_IRWXO : 819);
-or-
open(%trim(B64FileName) : O_RDWR + O_CREAT + O_TRUNC + O_CCSID : S_IRWXU + S_IRWXG + S_IRWXO : 65535);

The 819 file can be viewed using EDTF, and should look right.  Either file can be downloaded (binary download) to a PC or Linux machine and viewed using an ASCII text editor.

Of course, you'll then need to take the BASE64 string and convert it back to whatever it is supposed to represent.  BASE64 results are used to send binary data, so it could be UTF-8 XML, a PDF file, a JPG image, or anything.  You'll have to know what the result is in order to make sense of it once you decode it from BASE64.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Theo KouwenhovenApplication ConsultantAuthor Commented:
Hi Gary,

Close, but helped a lot.

Create it with CCSID 819, and then open it without O_TEXTDATA, but had to add CCSID=0.
In the debugging still not regonizable as base64 data, in the logging it is base64.

But.... Surprise, the field is type xsd_base64Binary???
while writing it to the IFS, it is writing PDF and not base64 :-)
Gary PattersonVP Technology / Senior Consultant Commented:
Hi Theo, it is hard for me to tell without seeing your code.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
RPGLE

From novice to tech pro — start learning today.