java.lang.RuntimeException:无法序列化

时间:2014-08-30 12:45:44

标签: java android web-services android-asynctask ksoap2

我已经编写了使用Web服务Mehod SaveOrder的代码。代码如下。

public final String SOAP_ACTION = "http://tempuri.org/SaveOrder";

public final String OPERATION_NAME = "SaveOrder";

public final String WSDL_TARGET_NAMESPACE = "http://tempuri.org/";

// public final String SOAP_ADDRESS =
// "http://mspldevad.cloudapp.net/order/Service.asmx";

// public final String SOAP_ADDRESS = "http://10.10.10.5:1212/Service.asmx";
public final String SOAP_ADDRESS = "http://10.10.10.5:101/Service.asmx";


public String SaveOrder(String Userid, String Latlong, String LocationID,
        String LabCount, String LabCodes, String IsOrder, byte[] image,
        String TubeCount) {

    SoapObject request = new SoapObject(WSDL_TARGET_NAMESPACE,OPERATION_NAME);

    PropertyInfo pi = new PropertyInfo();
    pi.setName("Userid");
    pi.setValue(Userid);
    pi.setType(String.class);
    request.addProperty(pi);

    pi = new PropertyInfo();
    pi.setName("Latlong");
    pi.setValue(Latlong);
    pi.setType(String.class);
    request.addProperty(pi);

    pi = new PropertyInfo();
    pi.setName("LocationID");
    pi.setValue(LocationID);
    pi.setType(String.class);
    request.addProperty(pi);

    pi = new PropertyInfo();
    pi.setName("LabCount");
    pi.setValue(LabCount);
    pi.setType(String.class);
    request.addProperty(pi);

    pi = new PropertyInfo();
    pi.setName("LabCodes");
    pi.setValue(LabCodes);
    pi.setType(String.class);
    request.addProperty(pi);

    pi = new PropertyInfo();
    pi.setName("IsOrder");
    pi.setValue(IsOrder);
    pi.setType(String.class);
    request.addProperty(pi);

    pi = new PropertyInfo();
    pi.setName("image");
    pi.setValue(image);
    pi.setType(byte[].class);
    request.addProperty(pi);


    pi = new PropertyInfo();
    pi.setName("TubeCount");
    pi.setValue(TubeCount);
    pi.setType(String.class);
    request.addProperty(pi);

    SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
    envelope.dotNet = true;
    envelope.setOutputSoapObject(request);

    HttpTransportSE httpTransport = new HttpTransportSE(SOAP_ADDRESS);
    Object response = null;
    try {

        httpTransport.call(SOAP_ACTION, envelope);
        response = envelope.getResponse();
    } catch (Exception exception) {
        response = exception.toString();
    }
    return response.toString();
}

代码抛出异常java.lang.RuntimeException:无法序列化:[B @ 40e42ec0

在httpTransport.call(SOAP_ACTION,envelope);

行中

有什么建议吗?

2 个答案:

答案 0 :(得分:0)

当它显示Cannot serialize: [B@40e42ec0时,它告诉您它无法序列化byte[]个对象。

事实上,我认为问题在于您使用byte[].classPropertyInfo image对象中指定类型。

根据另一个Q& A,它应该是MarshalBase64.BYTE_ARRAY_CLASS

参考:

答案 1 :(得分:0)

你可以像

那样做
Base64.encode(your Byte array variable)

发送时,例如

request.addProperty("Picture", Base64.encode(bmp100));

我已经解决了使用此问题,希望它能帮到你