MATLAB: Do I get a larger array when I try to read a ‘byte-array’ from the web service using the ‘createClassFromWsdl’ interface in MATLAB 7.12 (R2011a)

arraybase64bytedatadecodeencodeimportMATLABwebservice

I have a webservice that returns some data in the form of a byte-array in both my Java and C# client interfaces. However, if I read that same data into MATLAB using the 'createClassFromWsdl' interface, I get data whose size is larger than the expected array. Moreover, it consists of different data.

Best Answer

MATLAB returns the base64 encoded byte stream for any data that is sent over the SOAP message. Unlike C# or Java clients which interface to the webservice, MATLAB does not convert this data back to a binary byte array.
Base64 encoding takes every 3 bytes (24 bits) and encodes them into 4 bytes with 6 bits of data per byte. Each of these 4 bytes comes from a 64-byte dictionary of regular characters (e.g. A-Z,a-z, 0-9, / etc).
To get the raw byte data, manually decode this Base64 encoded data.
A small example of how to do this within MATLAB is shown below:
%Import Java
import java.lang.String;
%Import the base64 encoder object
encoder = org.apache.commons.codec.binary.Base64;
% Create a sample Base64 encoded string
bs64data = '7tyg546bf0a2316dhvber345' ;
% Create Java String
JavaString = String(bs64data);
% Extract the Bytes from this String
ByteFromString = JavaString.getBytes();
% Perform the Base64 Decoding - Output is int8 data format
DecodedBytes = encoder.decodeBase64(ByteFromString);