Undefinable output from WebService

Theo Kouwenhoven
Theo Kouwenhoven used Ask the Experts™
on
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 :
■&àã■■■■■■■■■■■?¦■■■■■■■è`
?ÀÁ■■íËÁ+?>Á■■■&/ÅÁ</`?ÍÈ■
■■■■■&Ê?ÀÍÄÁÊ■■&ÀÃäÊÁ/È?Ê■Î
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
VP 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.
Theo KouwenhovenApplication Consultant

Author

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.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial