title: Transferring byte array from soap service to android
body: <p>I have an android client that makes a request to a soap service. The soap service reads an image into a series of bytes and returns a byte array (quite a large one). Would this be seen as a primitive transfer type? The reason I ask is because I have the service code that reads an image and prints the first 5 bytes. Then it returns the byte array.</p>
  
  <pre><code>@Override
  public byte[] getImage() {
      byte[] imageBytes = null;
      try {
          File imageFile = new File("C:\\images\\car.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();
      }
      System.out.println("Got request");
      System.out.println("****** FIRST 5 BYTES: ");
      for(int i=0; i&lt;5; i++) {
          System.out.println("****** " + imageBytes[i]);
      }
      return imageBytes;
  }
  </code></pre>
  
  <p>The output from the service on the server is </p>
  
  <pre><code>****** FIRST 5 BYTES: 
  ****** -119
  ****** 80
  ****** 78
  ****** 71
  ****** 13
  </code></pre>
  
  <p>When I receive this on my android emulator, I print the first 5 bytes and they are completely different to those printed on the server. Here is my android code:</p>
  
  <pre><code>        androidHttpTransport.call(SOAP_ACTION, envelope);
          SoapPrimitive  resultsRequestSOAP = (SoapPrimitive) envelope.getResponse();
          String result = resultsRequestSOAP.toString();
          System.out.println("****** RESULT: " + result);
          byte[] b = result.getBytes();
          System.out.println("****** FIRST 5 BYTES: ");
          for(int i=0; i&lt;5; i++) {
              System.out.println("****** " + b[i]);
          }
  </code></pre>
  
  <p>And the output is </p>
  
  <pre><code>****** FIRST 5 BYTES: 
  ****** 105
  ****** 86
  ****** 66
  ****** 79
  ****** 82
  </code></pre>
  
  <p>It works fine if I test it with a simple service client written in java. Any ideas why this might be happening?</p>