Search code examples
androidbase64ksoap2

Android KSOAP2 base64Binary response from .net webservice


Im trying to get a byte[] from a base64Binary field in my android application. i manage to get the data though for some reason the data array is full with values in some places, where the same data array in C# returns positive numbers, for instance:

In C# webservice the byte array might look like 46,0,45..... and in android it looks like 46,0, -112......

how can i get the correct byte array from a base64Binary field with KASOP2?

this is the code im currently using:

SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME1);
request.addProperty("Name", sName);
SoapSerializationEnvelope envelope =
  new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.dotNet = true;
envelope.setOutputSoapObject(request);


try
{
HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
androidHttpTransport.call(SOAP_ACTION, envelope);
Object o = envelope.bodyIn;
SoapPrimitive result =  (SoapPrimitive)envelope.getResponse();
//to get the data should be a base
String resultData = result.toString();


} 

p.s i have run resultData through about 6 different base64 decoding classes and they all decode it wrong, so im guessing the problem is the the string returned by the response.

Any help will be greatly appreciated, Thanks, Totem


Solution

  • Actual my problem was very simple i forgot the servers were c++ therefore byte for the base64 encoding was unsigned, and all the classes i found for java were with byte. just had to remove the signed bit from the read stream like so:

    nextByte = (short)(0xFF & (short)buf[offset + i]);