Web Service Android Application : Cannot serialize 1.0 -
p.s : have looked @ similar questions haven't been able understand do. talk using marshal class, can't seem understand.
i creating android application consume jax-ws. using ksoap-2 library same.
i take inputs user in series of text fields , pass these onto webservice activity.
here in oncreate method call web service after setting soap object :
protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); // message intent intent intent = getintent(); bundle extras = intent.getextras(); string cropname = extras.getstring(androidwsclient.crop_name); float area = extras.getfloat(androidwsclient.area);
similarly names of fertilizers , add them arraylist called fertilizerlist. 3 more values in similar manner.
soapobject request = new soapobject(namespace, method_name); // add parameters soap object // cropname propertyinfo propinfo = new propertyinfo(); propinfo.name = "cropname"; propinfo.type = propertyinfo.string_class; request.addproperty(propinfo, cropname); system.out.println("!!!! success cropname !!!"); // area propinfo = new propertyinfo(); propinfo.setname("area"); propinfo.settype(double.class); request.addproperty(propinfo, area); system.out.println("!!!! success area !!!"); // fertilizerlist propinfo = new propertyinfo(); propinfo.setname("fertilizerlist"); propinfo.settype(arraylist.class); request.addproperty(propinfo, fertilizerlist); system.out.println("!!!! success fertilizerlist !!!"); // n value propinfo = new propertyinfo(); propinfo.setname("nitrogen"); propinfo.settype(integer.class); request.addproperty(propinfo, n); system.out.println("!!!! success n !!!");
here create soap object , properties it.
i need pass multiple parameters web service, order in add these properties order in they'll appear parameters web service, right ?
send out request web service :
// send out request web service soapserializationenvelope envelope = new soapserializationenvelope(soapenvelope.ver11); system.out.println("created envelope!"); envelope.setoutputsoapobject(request); system.out.println("reached set output object"); httptransportse androidhttptransport = new httptransportse(url); system.out.println("reached httptransport layer"); try { androidhttptransport.call(soap_action, envelope); soapprimitive resultsrequestsoap = (soapprimitive) envelope.getresponse(); textview textview = new textview(this); textview.settextsize(40); system.out.println(resultsrequestsoap.tostring()); textview.settext(resultsrequestsoap.tostring()); // set text view activity layout setcontentview(textview); } catch (exception e) { e.printstacktrace(); }
here output logcat :
07-11 05:37:32.782: i/system.out(1698): !!!! success cropname !!! 07-11 05:37:32.782: i/system.out(1698): !!!! success area !!! 07-11 05:37:32.792: i/system.out(1698): !!!! success fertilizerlist !!! 07-11 05:37:32.792: i/system.out(1698): !!!! success n !!! 07-11 05:37:32.872: i/system.out(1698): created envelope! 07-11 05:37:32.872: i/system.out(1698): reached set output object 07-11 05:37:32.912: i/system.out(1698): reached httptransport layer 07-11 05:37:33.012: w/system.err(1698): java.lang.runtimeexception: cannot serialize: 1.0 07-11 05:37:33.012: w/system.err(1698): @ org.ksoap2.serialization.soapserializationenvelope.writeelement(soapserializationenvelope.java:629) 07-11 05:37:33.022: w/system.err(1698): @ org.ksoap2.serialization.soapserializationenvelope.writeproperty(soapserializationenvelope.java:613) 07-11 05:37:33.032: w/system.err(1698): @ org.ksoap2.serialization.soapserializationenvelope.writeobjectbody(soapserializationenvelope.java:582) 07-11 05:37:33.032: w/system.err(1698): @ org.ksoap2.serialization.soapserializationenvelope.writeobjectbody(soapserializationenvelope.java:566) 07-11 05:37:33.062: w/system.err(1698): @ org.ksoap2.serialization.soapserializationenvelope.writeelement(soapserializationenvelope.java:623) 07-11 05:37:33.072: w/system.err(1698): @ org.ksoap2.serialization.soapserializationenvelope.writebody(soapserializationenvelope.java:547) 07-11 05:37:33.072: w/system.err(1698): @ org.ksoap2.soapenvelope.write(soapenvelope.java:192) 07-11 05:37:33.092: w/system.err(1698): @ org.ksoap2.transport.transport.createrequestdata(transport.java:74) 07-11 05:37:33.092: w/system.err(1698): @ org.ksoap2.transport.httptransportse.call(httptransportse.java:58) 07-11 05:37:33.112: w/system.err(1698): @ com.example.androidwsclient.webserviceactivity.oncreate(webserviceactivity.java:99) 07-11 05:37:33.112: w/system.err(1698): @ android.app.activity.performcreate(activity.java:5104) 07-11 05:37:33.132: w/system.err(1698): @ android.app.instrumentation.callactivityoncreate(instrumentation.java:1080)
implement marshal double
public class marshaldouble implements marshal { @override public object readinstance(xmlpullparser parser, string namespace, string name, propertyinfo expected) throws ioexception, xmlpullparserexception { return double.parsedouble(parser.nexttext()); } public void register(soapserializationenvelope cm) { cm.addmapping(cm.xsd, "double", double.class, this); } @override public void writeinstance(xmlserializer writer, object obj) throws ioexception { writer.text(obj.tostring()); } }
then call there register method in code.
new marshaldouble().register(envelope);
Comments
Post a Comment