我有一个Web服务,它接收complexType Pic的对象,
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;
}
}
}
我通过在信封双打和marshalBase64中注册将其发送到网络服务。到目前为止一切运行顺利,虽然在Web服务中,一旦我得到对象方法picture.imageInByte()返回null。我不确定发生了什么,因为我可以像这样传递一个byte []变量并将文件写入磁盘。但我只传递一个byte []而不是一个带有byte []的复杂对象。
有什么问题?
答案 0 :(得分:0)
我解决的方法是改变Web服务以接收2个参数而不是一个。
像这样:public void receivePicture(Pic picture, byte[] image){
}
其中picture是我需要的关于图像本身的信息,而image是实际的图像文件。
我知道这是一个黑客,而不是我正在寻找的好解决方案,但它有效。