Android accesses the Webservice interface, and parameter objects Cannot be serialized (java. lang. RuntimeException: Cannot serialize)

Source: Internet
Author: User

The Webservice Interface Parameters on the server end use custom struct and some non-generic string classes.

The Android client uses the ksoap2 jar package as follows:

// Call the method String methodName = "sceneUserValidate"; // create the httpTransportSE transmission object HttpTransportSE ht = new HttpTransportSE (SERVICE_URL); // service url ht. debug = true; // use the soap1.1 protocol to create the Envelop object SoapSerializationEnvelope envelope = new SoapSerializationEnvelope (SoapEnvelope. VER11); // instantiate SoapObject object SoapObject request = new SoapObject (SERVICE_NS, methodName);/*** set the parameter. The parameter name may not necessarily be the same as the parameter name on the called server, you only need to have the same order **/ SceneUserValidateEvt sevt = new SceneUserValidateEvt (); sevt. setCallNumber ("13913008213"); sevt. setInaccessInfo (new InaccessInfo ("0020001", "0020001", "12", "12", "v1.0"); request. addProperty ("SceneUserValidateEvt", sevt); // set the SoapObject object to envelope. bodyOut = request; envelope. setOutputSoapObject (request); Log. d ("haha", "start ="); try {// call webService ht. call (SER VICE_NS + methodName, envelope); Log. d ("haha", "dump =" + ht. requestDump); // txt1.setText ("look" + envelope. getResponse (); if (envelope. getResponse ()! = Null) {SoapObject result = (SoapObject) envelope. bodyIn; String name = result. getProperty (0 ). toString (); Log. d ("haha", "Return Value =" + name);} else {Log. d ("haha", "Return Value =! ") ;}} Catch (Exception e) {e. printStackTrace ();}

The following error occurs during running:

04-12 21:31:12. 046: W/System. err (4202): java. lang. RuntimeException: Cannot serialize: com. Alibaba. webservice_visit.SceneUserValidateEvt @ 41b1ec80
04-12 21:31:12. 046: W/System. err (4202): at org. ksoap2.serialization. SoapSerializationEnvelope. writeElement (SoapSerializationEnvelope. java: 664)
04-12 21:31:12. 046: W/System. err (4202): at org. ksoap2.serialization. SoapSerializationEnvelope. writeProperty (SoapSerializationEnvelope. java: 649)
04-12 21:31:12. 046: W/System. err (4202): at org. ksoap2.serialization. SoapSerializationEnvelope. writeObjectBody (SoapSerializationEnvelope. java: 604)
04-12 21:31:12. 046: W/System. err (4202): at org. ksoap2.serialization. SoapSerializationEnvelope. writeObjectBody (SoapSerializationEnvelope. java: 582)
04-12 21:31:12. 046: W/System. err (4202): at org. ksoap2.serialization. SoapSerializationEnvelope. writeElement (SoapSerializationEnvelope. java: 658)
04-12 21:31:12. 046: W/System. err (4202): at org. ksoap2.serialization. SoapSerializationEnvelope. writeBody (SoapSerializationEnvelope. java: 564)
04-12 21:31:12. 056: W/System. err (4202): at org. ksoap2.SoapEnvelope. write (SoapEnvelope. java: 205)
04-12 21:31:12. 056: W/System. err (4202): at org. ksoap2.transport. Transport. createRequestData (Transport. java: 111)
04-12 21:31:12. 056: W/System. err (4202): at org. ksoap2.transport. HttpTransportSE. call (HttpTransportSE. java: 121)
04-12 21:31:12. 056: W/System. err (4202): at org. ksoap2.transport. HttpTransportSE. call (HttpTransportSE. java: 96)
04-12 21:31:12. 056: W/System. err (4202): at com. Alibaba. webservice_visit.MainActivity.startWebservice (MainActivity. java: 72)
04-12 21:31:12. 056: W/System. err (4202): at com. Alibaba. webservice_visit.MainActivity.access $0 (MainActivity. java: 40)
04-12 21:31:12. 056: W/System. err (4202): at com. Alibaba. webservice_visit.MainActivity $ 2.run( MainActivity. java: 113)

04-12 21:31:12. 056: W/System. err (4202): at java. lang. Thread. run (Thread. java: 856)


The first response is to execute the SceneUserValidateEvt struct implements Serializable, but the above error is still prompted after running.


Most cases of goolge serialization failure do not match mine. Many cases of Integer. class serialization failure are found on the Internet. However, I thought about the ksoap package later.

There is an interface class org. ksoap2.serialization. KvmSerializable;


I tried to implements the SceneUserValidateEvt struct.KvmSerializableAnd the following four interfaces are implemented. The operation is successful.

public abstract interface org.ksoap2.serialization.KvmSerializable {    // Method descriptor #4 (I)Ljava/lang/Object;  public abstract java.lang.Object getProperty(int arg0);    // Method descriptor #6 ()I  public abstract int getPropertyCount();    // Method descriptor #8 (ILjava/lang/Object;)V  public abstract void setProperty(int arg0, java.lang.Object arg1);    // Method descriptor #10 (ILjava/util/Hashtable;Lorg/ksoap2/serialization/PropertyInfo;)V  public abstract void getPropertyInfo(int arg0, java.util.Hashtable arg1, org.ksoap2.serialization.PropertyInfo arg2);}

The Android client can access the Webservice Interface normally.


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.