android - How to parse <strxml>String</strxml> using soap? -
this soap webservice.i have donn. bt got error.this code.can me.how parse string in android. int string int int string string in advance.
public boolean callwebservice() { boolean result = false; int patid = 1; string xml = ""; soapobject request = new soapobject(namespace, method_name); request.addproperty("patientid", patid); request.addproperty("appointmentdate", appdate); request.addproperty("timefrom", apptimeto); request.addproperty("timeto", appfrom); request.addproperty("reasonforappointment", appreason); request.addproperty("strxml", xml); soapserializationenvelope envelope = new soapserializationenvelope( soapenvelope.ver11); envelope.dotnet = true; envelope.setoutputsoapobject(request); httptransportse httptransport = new httptransportse(url); httptransport.debug = true; try { httptransport.call(soap_action, envelope); httptransport .setxmlversiontag("<?xml version=\"1.0\" encoding=\"utf-8\"?>"); // soapobject response = (soapobject) envelope.bodyin; soapprimitive response = (soapprimitive) envelope.getresponse(); system.out.println("myapp" + response.tostring()); system.out.println("response" + response); if (response.tostring().equalsignorecase("false")) { result = true; } } catch (socketexception ex) { system.out.println("error : " + "error on soapprimitivedata() " + ex.getmessage()); ex.printstacktrace(); } catch (exception e) { system.out.println("error : " + "error on soapprimitivedata() " + e.getmessage()); e.printstacktrace(); } return result;
first import ksoap2 library project , try this.here link
public class mainactivity extends activity { private final string namespace = "http://www.webservicex.net/"; private final string url = "http://www.webservicex.net/currencyconvertor.asmx"; private final string soap_action = "http://www.webservicex.net/conversionrate"; private final string method_name = "conversionrate"; soapobject request; string weight; string fromunit; string tounit; /** called when activity first created. */ @override public void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_main); request = new soapobject(namespace, method_name); weight = "usd"; fromunit = "inr"; tounit = "kilograms"; propertyinfo weightprop =new propertyinfo(); weightprop.setname("fromcurrency"); weightprop.setvalue(weight); weightprop.settype(string.class); request.addproperty(weightprop); propertyinfo fromprop =new propertyinfo(); fromprop.setname("tocurrency"); fromprop.setvalue(fromunit); fromprop.settype(string.class); request.addproperty(fromprop); //calling asynctask new task().execute(); } class task extends asynctask<void, void, void>{ soapprimitive response; @override protected void doinbackground(void... params) { soapserializationenvelope envelope = new soapserializationenvelope(soapenvelope.ver11); envelope.dotnet = true; envelope.setoutputsoapobject(request); httptransportse androidhttptransport = new httptransportse(url); try { androidhttptransport.call(soap_action, envelope); response = (soapprimitive)envelope.getresponse(); log.i("myapp", ""+response); } catch (exception e) { e.printstacktrace(); } // todo auto-generated method stub return null; } @override protected void onpostexecute(void result) { // todo auto-generated method stub textview tv = new textview(getapplicationcontext()); tv.settext("1"+weight+" equals "+response.tostring()+ " "+fromunit); tv.settextsize(50); setcontentview(tv); super.onpostexecute(result); } } @override public boolean oncreateoptionsmenu(menu menu) { // inflate menu; adds items action bar if present. getmenuinflater().inflate(r.menu.main, menu); return true; }
}
Comments
Post a Comment