开发者

Android KSOAP2 base64Binary response from .net webservice

开发者 https://www.devze.com 2023-02-06 12:35 出处:网络
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 ar

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


I had the exact same problem, then I stepped on this link http://androidcodemonkey.blogspot.com/2010/03/how-to-base64-encode-decode-android.html

I downloaded the Base64 class from Robert W. Harder's site and it worked, the only thing I did was to add my package definition in the class itself just so that I could use it.

Note: I'm working with Android 1.6 so I can assume it works upwards.

Hope this helps :)


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]);
0

精彩评论

暂无评论...
验证码 换一张
取 消