@Michael, it worked a charm. Here is my last working code that will send jpeg from the soap service to the Android emulator and show it. I am using jax-ws. The following is an implementation of the bean service for the getImage () operation, which returns a base64 encoded string of image bytes.
@Override public String getImage() { byte[] imageBytes = null; try { File imageFile = new File("C:\\images\\fiesta.jpg"); BufferedImage img = ImageIO.read(imageFile); ByteArrayOutputStream baos = new ByteArrayOutputStream(1000); ImageIO.write(img, "jpg", baos); baos.flush(); imageBytes = baos.toByteArray(); baos.close(); } catch (IOException ioe) { ioe.printStackTrace(); } return (imageBytes != null) ? Base64.encodeBase64String(imageBytes) : ""; }
Now here is the Android code that will call the service and receive the contents of the encoded image, decode it into an array of bytes, create bitmap images and display them in the emulator:
public class ImageSoapActivity extends Activity { private static final String NAMESPACE = "http://image.webservice"; private static final String URL = "http://10.0.2.2:8080/images?wsdl"; private static final String METHOD_NAME = "getImage"; private static final String SOAP_ACTION = "http://image.webservice/getImage"; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME); SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11); envelope.setOutputSoapObject(request); HttpTransportSE androidHttpTransport = new HttpTransportSE(URL); try { androidHttpTransport.call(SOAP_ACTION, envelope); SoapPrimitive resultsRequestSOAP = (SoapPrimitive) envelope.getResponse(); String result = resultsRequestSOAP.toString(); if (result != "") { byte[] bloc = Base64.decode(result, Base64.DEFAULT); Bitmap bmp = BitmapFactory.decodeByteArray(bloc,0,bloc.length); ImageView image = new ImageView(this); image.setImageBitmap(bmp); setContentView(image); } } catch (Exception e) { System.out.println("******* THERE WAS AN ERROR ACCESSING THE WEB SERVICE"); e.printStackTrace(); } } }

I hope this is useful for someone who might need it. You must also set the permission: <uses-permission android:name="android.permission.INTERNET"></uses-permission> . Also note that the emulator connects to the localhost machine at 10.0.2.2, not 127.0.0.1
source share