How To handle SOAP Request and response in android -


i'm developing app in m handling web service using soap request , response. can 1 please tell me how handle soap request , response? have read of tutorial tutorial not understood. click here

public class stockquotefetcher {      private final string namespace = "https://book.mylimobiz.com/api";     private final string method_name = "getcars";     private final string soap_action ="https://book.mylimobiz.com/api/getcars";     private final string url = "https://book.mylimobiz.com/api/apiservice.asmx?wsdl";     private final soapserializationenvelope envelope;      public stockquotefetcher(string apiid, string apikey)     {         soapobject request = new soapobject(namespace, method_name);          propertyinfo quotesproperty = new propertyinfo();         quotesproperty.setname("apiid");         quotesproperty.setvalue(apiid);         quotesproperty.settype(string.class);         request.addproperty(quotesproperty);         propertyinfo quotesproperty1 = new propertyinfo();         quotesproperty1.setname("apikey");         quotesproperty1.setvalue(apikey);         quotesproperty1.settype(string.class);         request.addproperty(quotesproperty1);          envelope = new soapserializationenvelope(soapenvelope.ver11);         envelope.dotnet = true;         envelope.setoutputsoapobject(request);     }      public  list<car> fetch()     {         httptransportse httprequest = new httptransportse(url);         handler quoteparser = new handler();;         try         {             httprequest.call(soap_action, envelope);             soapobject resultsstring = (soapobject) envelope.getresponse();             xml.parse(resultsstring.tostring(), quoteparser);             //result =  resultsstring.tostring();         }         catch(exception e)         {             e.printstacktrace();         }         return quoteparser.getcar();     } }  public class handler extends defaulthandler {      private arraylist<car> quotes = new arraylist<car>();     private car currentquote;     private string currentnodetext;      private final string car = "car";     private final string car_id = "carid";     private final string car_code = "carcode";     private final string car_name = "carname";     private final string car_type = "cartype";     private final string cell_phone = "cellphone";     private final string two_way_radio_id = "twowayradioid";      @override     public void startelement(string uri, string localname, string qname,             attributes attributes) throws saxexception {         // create new stockquote every corresponding         // <stock> node in xml document         if (localname.equalsignorecase(car)) {             currentquote = new car();         }     }      @override     public void characters(char[] ch, int start, int length)             throws saxexception {         // retrieve text content of current node         // being processed         currentnodetext = new string(ch, start, length);     }      @override     public void endelement(string uri, string localname, string qname)             throws saxexception {         if(localname.equalsignorecase(car_id)){             currentquote.setcarid(car_id);         }else if(localname.equalsignorecase(car_type)){             currentquote.setcartype(car_type);         }else if(localname.equalsignorecase(car_name)){             currentquote.setcarname(car_name);         }else if(localname.equalsignorecase(car)){             // when </stock> element reached, quote object complete.             quotes.add(currentquote);         }     }      public arraylist<car> getcar()     {         return quotes;     } } 

you should use ksoap2 jar. , documentation here.

to call web-service, use following lines

soapserializationenvelope envelope = new soapserializationenvelope(soapenvelope.ver11); soapobject request = new soapobject(namespace, method); //bodyout body object sent out envelope envelope.bodyout = request; httptransportse transport = new httptransportse(url); transport.call(namespace + soap_action_prefix + method, envelope);  

envelope.bodyout used send soap body web service, envelop.bodyin used receive response web service.

soapprimitive resultsoap = (soapprimitive) ((soapobject) envelope.bodyin).getproperty(0); response=resultsoap.tostring(); 

Comments

Popular posts from this blog

java - Plugin org.apache.maven.plugins:maven-install-plugin:2.4 or one of its dependencies could not be resolved -

Round ImageView Android -

How can I utilize Yahoo Weather API in android -