Why do I get a larger array when I try to read a 'byte-array' from my web service using the 'createClassFromWsdl' interface in MATLAB 7.12 (R2011a)?

1 Ansicht (letzte 30 Tage)
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.

Akzeptierte Antwort

MathWorks Support Team
MathWorks Support Team am 11 Nov. 2011
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);

Weitere Antworten (0)

Kategorien

Mehr zu Call Java from MATLAB finden Sie in Help Center und File Exchange

Produkte


Version

R2011a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by