2013-12-14 84 views
1

我有一個接收復雜類型產品圖的對象的Web服務,ksoap2 Android的Web服務複雜類型的byte []

Pic.java

public class Pic implements KvmSerializable{ 

    private double latitude; 
    private double longitude; 
    private long time; 
    private double accuracy; 
    private String name; 
    private byte[] imageInByte; 

    public byte[] getImageInByte() { 
     return imageInByte; 
    } 
    public void setImageInByte(byte[] imageInByte) { 
     this.imageInByte = imageInByte; 
    } 
    public String getName() { 
     return name; 
    } 
    public void setName(String name) { 
     this.name = name; 
    } 
    public double getLatitude() { 
     return latitude; 
    } 
    public void setLatitude(double latitude) { 
     this.latitude = latitude; 
    } 
    public double getLongitude() { 
     return longitude; 
    } 
    public void setLongitude(double longitude) { 
     this.longitude = longitude; 
    } 
    public double getAccuracy() { 
     return accuracy; 
    } 
    public void setAccuracy(double accuracy) { 
     this.accuracy = accuracy; 
    } 
    public long getTime() { 
     return time; 
    } 
    public void setTime(long time) { 
     this.time = time; 
    } 

    @Override 
    public Object getProperty(int arg0) { 
     switch(arg0){ 
     case 0: 
      return latitude; 
     case 1: 
      return longitude; 
     case 2: 
      return time; 
     case 3: 
      return accuracy; 
     case 4: 
      return name; 
     case 5: 
      return imageInByte; 
     } 
     return null; 
    } 
    @Override 
    public int getPropertyCount() { 
     return 6; 
    } 
    @Override 
    public void getPropertyInfo(int arg0, Hashtable arg1, PropertyInfo arg2) { 
     switch(arg0){ 
     case 0: 
      arg2.type = PropertyInfo.STRING_CLASS; 
      arg2.name = "latitude"; 
      break; 
     case 1: 
      arg2.type = PropertyInfo.STRING_CLASS; 
      arg2.name = "longitude"; 
      break; 
     case 2: 
      arg2.type = PropertyInfo.LONG_CLASS; 
      arg2.name = "time"; 
      break; 
     case 3: 
      arg2.type = Double.class; 
      arg2.name = "accuracy"; 
      break; 
     case 4: 
      arg2.type = PropertyInfo.STRING_CLASS; 
      arg2.name = "name"; 
      break; 
     case 5: 
      arg2.type = MarshalBase64.BYTE_ARRAY_CLASS; 
      arg2.name = "imageInBytes"; 
     default: 
      break; 
     } 
    } 
    @Override 
    public void setProperty(int arg0, Object arg1) { 
     // TODO Auto-generated method stub 
     switch(arg0){ 
     case 0: 
      latitude = Double.parseDouble(arg1.toString()); 
      break; 
     case 1: 
      longitude = Double.parseDouble(arg1.toString()); 
      break; 
     case 2: 
      time = Long.parseLong(arg1.toString()); 
      break; 
     case 3: 
      accuracy = Double.parseDouble(arg1.toString()); 
      break; 
     case 4: 
      name = arg1.toString(); 
      break; 
     case 5: 
       imageInByte = Base64.decode(arg1.toString(), Base64.DEFAULT); 
        break; 
    default: 
      break; 
     } 
    } 
} 

我在信封雙打註冊其發送到WebService和marshalBase64。到目前爲止一切運行順利,雖然在Web服務中,一旦我得到對象的方法picture.imageInByte()返回null。我不確定發生了什麼,因爲我可以像這樣傳遞一個byte []變量並將文件寫入磁盤。但我只傳遞了一個byte []而不是一個帶有byte []的複雜對象。

什麼問題?

回答

0

我解決的方法是通過更改Web服務來接收2個參數而不是一個參數。

這樣的:

public void receivePicture(Pic picture, byte[] image){ 

} 

,其中圖片是我需要對圖像本身和圖像的信息是實際的圖像文件。

我知道這是某種方式的破解,並不完全是我尋找的好解決方案,但它的工作原理。