Android Ksoap 调用webservice 获取二进制数据 byte[] 方法
2014-12-14 22:23
417 查看
由于Ksoap 调用远程方法返回的结果是 String即便远程服务器返回方法是 byte[] 数据,但是经过 ksoap 返回的是仍String,如果我们将返回的 String 直接转换为 byte[]后发现结果是不正确的 或者无法强制转换。
我们只需要简单的2步就可以进行结果的 正确强制转换:
1.远程调用前对 envelope 对象进行MarshalBase64 注册2.获取结果后 对结果进行Base64解码编码代码如下:private static byte[] serviceBinRCP(SoapObject soapObject,String action) { SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11); envelope.setOutputSoapObject(soapObject); new MarshalBase64().register(envelope);//1.远程调用前对 envelope 对象进行MarshalBase64 注册 HttpTransportSE se = new HttpTransportSE(url); Object result = null; byte []image = null; try { se.call(action,envelope); result = envelope.getResponse(); if (result != null) { image = Base64.decode(result.toString());//2.获取结果后 对结果进行Base64解码编码 } } catch (Exception e) { return null;//todo throw yourException } return image; }
相关文章推荐
- Android上访问Java做的WebService获取JSON数据的方法及org.xmlpull.v1.XmlPullParserException异常处理
- webservice 优化性能的方法,以返回Dataset为例,当大数据量时采用先压缩的方式,调用再解压缩
- Jquery Ajax学习实例3 向WebService发出请求,调用方法返回数据
- android中使用ksoap调用webservice
- Android通过ksoap调用webservice遇到的问题及解决之道全纪录
- Android使用ksoap2调用C#中的webservice函数方法
- webservice 优化性能的方法,以返回Dataset为例,当大数据量时采用先压缩的方式,调用再解压缩
- 写给痛苦于新旧语言交互中的新人们,vb6调用vs2005的webservice数据(方法一)
- Android发送SOAP数据给服务器调用webservice,实现手机号归属地查询
- Android获取网页数据的方法总结
- C#中通过调用webService获取上网IP地址的区域的方法
- Java从网络获取股票实时数据,2种方法webservice和javascript
- android调用.Net WebService传递byte[]
- ASP.NET 2.0 客户端无刷新调用服务器端方法获取数据
- JQuery调用webservice,返回的json数据和XML数据的处理方法
- Android 客户端调用基于XFire的webService方法传递自定义对象
- 在客户端调用WebService服务获取数据
- 万能android调用webservice方法——参数类型不受限制
- 转载 Android获取网页数据的方法总结
- C#中通过调用webService获取上网IP地址的区域的方法