[英]ksoap2 android web services complextype byte[]
I have a web service that receives an object of complexType Pic, 我有一个Web服务,接收一个complexType Pic对象,
Pic.java 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;
}
}
}
I send it to a webservice by registering in the envelope doubles and marshalBase64. 我通过在信封双打和marshalBase64中进行注册将其发送到Web服务。 So far everything runs smoothly although in the web service once i get the object the method picture.imageInByte() returns null.
到目前为止,尽管在Web服务中,一旦我获得对象,一切都将顺利进行,方法picture.imageInByte()返回null。 I am not sure of what is happening because i could pass just a byte[] variable like this and write the file to disk.
我不确定发生了什么,因为我只能传递像这样的byte []变量并将文件写入磁盘。 But i only passed a byte[] not a complex object with a byte[] inside.
但是我只传递了一个byte []而不是一个内部包含byte []的复杂对象。
What is the problem? 问题是什么?
The way i solved was by altering the web service to receive 2 parameters instead of one. 我解决的方法是将Web服务更改为接收2个参数而不是一个。
like this: 像这样:
public void receivePicture(Pic picture, byte[] image){
}
where picture is the information i need about the image itself and image is the actual image file. 图片是我需要的有关图像本身的信息,而图像是实际的图像文件。
I know this is somehow a hack and not exactly the good solution i was looking for but it works. 我知道这在某种程度上是一种hack,并不是我一直在寻找的好解决方案,但是它可以工作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.