简体   繁体   中英

How to retrieve binary data from Web Service in Android?

   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?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM