android - Error in getting a response from web service -


i created android app must connect web service (created me), stores in database (hosted in site of free hosting). web service takes latitude, longitude , text store in db , works great if use it.

but can't use web service android app. here code:

package com.example.mobile;  import java.io.ioexception;  import org.ksoap2.soapenvelope; import org.ksoap2.serialization.soapobject; import org.ksoap2.serialization.soapprimitive; import org.ksoap2.serialization.soapserializationenvelope; import org.ksoap2.transport.httptransportse; import org.xmlpull.v1.xmlpullparserexception;  import android.os.bundle; import android.app.activity; import android.content.intent; import android.util.log; import android.view.menu; import android.view.view; import android.view.view.onclicklistener; import android.widget.button; import android.widget.textview; import android.os.asynctask;   public class webserviceactivity extends activity implements onclicklistener {      public final static string soap_action1 = "http://ocrwebservice.somee.com/insertintodb";     public final static string soap_action2 = "http://ocrwebservice.somee.com/testing";     public final static string namespace = "http://ocrwebservice.somee.com/";     public final static string method_name1 = "insertintodb";     public final static string method_name2 = "testing";     public final static string url = "http://ocrwebservice.somee.com/service1.asmx?wsdl";      bundle extras;     textview tvresult;     button btnmenu;     string ocr;     int test_or_train; //valore sentinella     string gps, latitude, longitude;     double latitudine, longitudine;      @override     protected void oncreate(bundle savedinstancestate) {         super.oncreate(savedinstancestate);         setcontentview(r.layout.activity_web_service);          tvresult = (textview)findviewbyid(r.id.textviewresult);         btnmenu = (button)findviewbyid(r.id.buttongotomenu);          extras = getintent().getextras();         ocr = extras.getstring(recognitionactivity.ocrtext);         gps = extras.getstring(recognitionactivity.gps);         test_or_train = extras.getint(recognitionactivity.test_or_train);          string [] coordinate = gps.split("#");         latitude = coordinate[0];         longitude = coordinate[1];          log.d("valori", latitude);         log.d("valori", longitude);          //latitudine = double.parsedouble(latitude);         //longitudine = double.parsedouble(longitude);          system.out.println(latitudine);         system.out.println(longitudine);          asynccallws task = new asynccallws();         task.execute();      }      private class asynccallws extends asynctask<void,void,void>{         @override         protected void doinbackground(void... params) {             // todo auto-generated method stub             perform();             return null;         }     }      void perform(){         switch(test_or_train){         case 0: //inserimento dei valori -- fase di training             soapobject requestinsert = new soapobject(namespace, method_name1);//inizializzazione richiesta soap e aggiunta parametri              //aggiunta dei parametri per la richiesta soap                   requestinsert.addproperty("latitudine", latitude);             requestinsert.addproperty("longitudine", longitude);             requestinsert.addproperty("testo", ocr);              //dichiarazione della versione soap utilizzata             soapserializationenvelope insertenvelope = new soapserializationenvelope(soapenvelope.ver11);             insertenvelope.setoutputsoapobject(requestinsert);             insertenvelope.dotnet = true;               try {                 httptransportse inserttransport = new httptransportse(url);                  //chiamata del web service                 inserttransport.call(soap_action1, insertenvelope);                  soapprimitive insertresult = (soapprimitive)insertenvelope.getresponse();                  if(insertresult != null)                     tvresult.settext(insertresult.tostring());                 } catch (ioexception e) {                 // todo auto-generated catch block                     e.printstacktrace();                 } catch (xmlpullparserexception e) {                 // todo auto-generated catch block                     e.printstacktrace();                 }             break;          case 1:             soapobject requesttest = new soapobject(namespace, method_name2);              requesttest.addproperty("latitudine", latitudine);             requesttest.addproperty("longitudine", longitudine);             requesttest.addproperty("testo", ocr);              soapserializationenvelope testenvelope = new soapserializationenvelope(soapenvelope.ver11);             testenvelope.setoutputsoapobject(requesttest);             testenvelope.dotnet = true;              try{                 httptransportse testtransport = new httptransportse(url);                  testtransport.call(soap_action2, testenvelope);                  soapobject testresult = (soapobject)testenvelope.bodyin;                  if(testresult != null){                       if((testresult.getproperty(0).tostring()).compareto("exists") == 0)                         tvresult.settext("il cartello fotografato è presente nel db");                     else                         tvresult.settext("attenzione! il cartello fotografato non è presente nel db");                     }                  }catch (ioexception e) {                 // todo auto-generated catch block                     e.printstacktrace();                 } catch (xmlpullparserexception e) {                 // todo auto-generated catch block                     e.printstacktrace();                 }             break;              }         btnmenu.setonclicklistener(this);     }      @override     public boolean oncreateoptionsmenu(menu menu) {         // inflate menu; adds items action bar if present.         getmenuinflater().inflate(r.menu.activity_web_service, menu);         return true;     }      @override     public void onclick(view arg0) {         // todo auto-generated method stub         intent intentreset = new intent(this,mainactivity.class);         startactivity(intentreset);     } } 

and log cat get:

05-02 15:44:46.530: w/system.err(4670): soapfault - faultcode: 'soap:server' faultstring: 'server unable process request. ---> have error in sql syntax; check manual corresponds mysql server version right syntax use near ''po '')' @ line 1' faultactor: 'null' detail: org.kxml2.kdom.node@41934a08 05-02 15:44:46.530: w/system.err(4670):     @ org.ksoap2.serialization.soapserializationenvelope.parsebody(soapserializationenvelope.java:141) 05-02 15:44:46.530: w/system.err(4670):     @ org.ksoap2.soapenvelope.parse(soapenvelope.java:140) 05-02 15:44:46.540: w/system.err(4670):     @ org.ksoap2.transport.transport.parseresponse(transport.java:116) 05-02 15:44:46.540: w/system.err(4670):     @ org.ksoap2.transport.httptransportse.call(httptransportse.java:259) 05-02 15:44:46.540: w/system.err(4670):     @ org.ksoap2.transport.httptransportse.call(httptransportse.java:114) 

maybe there problem while call soap method, don't know how fix it.

your code seems calling soap method correctly. problem on web service itself.

try envelope:

<soapenv:envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"                   xmlns:ocr="http://ocrwebservice.somee.com/">    <soapenv:header/>    <soapenv:body>       <ocr:insertintodb>          <ocr:latitudine>33</ocr:latitudine>          <ocr:longitudine>44</ocr:longitudine>          <ocr:testo>po '</ocr:testo>       </ocr:insertintodb>    </soapenv:body> </soapenv:envelope> 

it yeld same error pointed:

<soap:envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"                xmlns:xsi="http://www.w3.org/2001/xmlschema-instance"                xmlns:xsd="http://www.w3.org/2001/xmlschema">    <soap:body>       <soap:fault>          <faultcode>soap:server</faultcode>          <faultstring>server unable process request. ---> have          error in sql syntax; check manual corresponds           mysql server version right syntax use near ''po '')' @           line 1</faultstring>          <detail/>       </soap:fault>    </soap:body> </soap:envelope> 

on other hand, when take ' out:

<soapenv:envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"                   xmlns:ocr="http://ocrwebservice.somee.com/">    <soapenv:header/>    <soapenv:body>       <ocr:insertintodb>          <ocr:latitudine>33</ocr:latitudine>          <ocr:longitudine>44</ocr:longitudine>          <ocr:testo>po </ocr:testo>       </ocr:insertintodb>    </soapenv:body> </soapenv:envelope> 

the insert sucessful.

bottom line is: either client or web service have escape ' properly.

my opinion? should done in web service , not in client because unproper escaping leaves service vulnerable sql injection. po ' not invalid string per se , service should not generate fault that.


Comments

Popular posts from this blog

linux - Does gcc have any options to add version info in ELF binary file? -

android - send complex objects as post php java -

charts - What graph/dashboard product is facebook using in Dashboard: PUE & WUE -