How to retrieve binary data from Web Service in Android?

我怕爱的太早我们不能终老 提交于 2019-12-08 04:22:05

问题


   SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);          
   Log.d("WebService", "2");
   SoapSerializationEnvelope envelope = 
          new SoapSerializationEnvelope(SoapEnvelope.VER11);
   envelope.dotNet = true;
   envelope.setOutputSoapObject(request);
   HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
   androidHttpTransport.call(SOAP_ACTION, envelope);                    
   SoapPrimitive result = (SoapPrimitive)envelope.getResponse();

This is the code where I call a .NET web service which sends a byte[] array. How can I get the byte[] array from the result variable or is there another approach to retrieve byte[] array?


回答1:


Assuming that the presented code is using kSoap2. If you want to access the retrieved data forget about the response object returned by envelope.getResponse().

The data you are looking for can be retrieved via

SoapObject resultsRequestSOAP = (SoapObject) envelope.bodyIn;
if (resultsRequestSOAP != null) {
  Object o = resultsRequestSOAP.getProperty("name of the byte-array parameter");
  // ...
}

The returned Object o is usually of the type SoapPrimitive or may be a Vector.

If it's a SoapPrimitive using it's toString() method you can get the String representation of the byte array that has to be parsed and converted to a byte array.

If it's a Vector I don't think that you will have problems converting it to a byte array.



来源:https://stackoverflow.com/questions/6383746/how-to-retrieve-binary-data-from-web-service-in-android

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!