Call SOAP service from android with ksoap error -
this question has answer here:
i have webservice running on google app engine, , call available service android device. i've follow , merge code of tutorial ksoap2, still obtain exception on android. code:
private static string method_name = "getdata"; private static string soap_action = "http://example.com/getdata"; private static string wsdl_url = "http://arduino-data-server.appspot.com/functionsservice.wsdl"; private static string namespace = "http://example.com/"; soapobject request = new soapobject(namespace, method_name); soapserializationenvelope envelope = new soapserializationenvelope( soapenvelope.ver12); envelope.setoutputsoapobject(request); httptransportse androidhttptransport = new httptransportse(wsdl_url); try { androidhttptransport.call(soap_action, envelope); soapobject result = (soapobject) envelope.getresponse(); if (result != null) { textview t = (textview) this.findviewbyid(r.id.text_view); t.settext("soap response:\n\n"+ result.getproperty(0).tostring()); } } catch (ioexception e) { // todo auto-generated catch block e.printstacktrace(); } catch (xmlpullparserexception e) { // todo auto-generated catch block e.printstacktrace(); }
and that's error log:
09-03 18:09:04.805: w/dalvikvm(28352): threadid=1: thread exiting uncaught exception (group=0x41909700) 09-03 18:09:04.821: e/androidruntime(28352): fatal exception: main 09-03 18:09:04.821: e/androidruntime(28352): java.lang.runtimeexception: unable start activity componentinfo{com.example.provasoap/com.example.provasoap.mainactivity}: android.os.networkonmainthreadexception 09-03 18:09:04.821: e/androidruntime(28352): @ android.app.activitythread.performlaunchactivity(activitythread.java:2211) 09-03 18:09:04.821: e/androidruntime(28352): @ android.app.activitythread.handlelaunchactivity(activitythread.java:2261) 09-03 18:09:04.821: e/androidruntime(28352): @ android.app.activitythread.access$600(activitythread.java:141) 09-03 18:09:04.821: e/androidruntime(28352): @ android.app.activitythread$h.handlemessage(activitythread.java:1256) 09-03 18:09:04.821: e/androidruntime(28352): @ android.os.handler.dispatchmessage(handler.java:99) 09-03 18:09:04.821: e/androidruntime(28352): @ android.os.looper.loop(looper.java:137) 09-03 18:09:04.821: e/androidruntime(28352): @ android.app.activitythread.main(activitythread.java:5103) 09-03 18:09:04.821: e/androidruntime(28352): @ java.lang.reflect.method.invokenative(native method) 09-03 18:09:04.821: e/androidruntime(28352): @ java.lang.reflect.method.invoke(method.java:525) 09-03 18:09:04.821: e/androidruntime(28352): @ com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:737) 09-03 18:09:04.821: e/androidruntime(28352): @ com.android.internal.os.zygoteinit.main(zygoteinit.java:553) 09-03 18:09:04.821: e/androidruntime(28352): @ dalvik.system.nativestart.main(native method) 09-03 18:09:04.821: e/androidruntime(28352): caused by: android.os.networkonmainthreadexception 09-03 18:09:04.821: e/androidruntime(28352): @ android.os.strictmode$androidblockguardpolicy.onnetwork(strictmode.java:1133) 09-03 18:09:04.821: e/androidruntime(28352): @ java.net.inetaddress.lookuphostbyname(inetaddress.java:385) 09-03 18:09:04.821: e/androidruntime(28352): @ java.net.inetaddress.getallbynameimpl(inetaddress.java:236) 09-03 18:09:04.821: e/androidruntime(28352): @ java.net.inetaddress.getallbyname(inetaddress.java:214) 09-03 18:09:04.821: e/androidruntime(28352): @ libcore.net.http.httpconnection.<init>(httpconnection.java:70) 09-03 18:09:04.821: e/androidruntime(28352): @ libcore.net.http.httpconnection.<init>(httpconnection.java:50) 09-03 18:09:04.821: e/androidruntime(28352): @ libcore.net.http.httpconnection$address.connect(httpconnection.java:340) 09-03 18:09:04.821: e/androidruntime(28352): @ libcore.net.http.httpconnectionpool.get(httpconnectionpool.java:87) 09-03 18:09:04.821: e/androidruntime(28352): @ libcore.net.http.httpconnection.connect(httpconnection.java:128) 09-03 18:09:04.821: e/androidruntime(28352): @ libcore.net.http.httpengine.opensocketconnection(httpengine.java:316) 09-03 18:09:04.821: e/androidruntime(28352): @ libcore.net.http.httpengine.connect(httpengine.java:311) 09-03 18:09:04.821: e/androidruntime(28352): @ libcore.net.http.httpengine.sendsocketrequest(httpengine.java:290) 09-03 18:09:04.821: e/androidruntime(28352): @ libcore.net.http.httpengine.sendrequest(httpengine.java:240) 09-03 18:09:04.821: e/androidruntime(28352): @ libcore.net.http.httpurlconnectionimpl.connect(httpurlconnectionimpl.java:81) 09-03 18:09:04.821: e/androidruntime(28352): @ libcore.net.http.httpurlconnectionimpl.getoutputstream(httpurlconnectionimpl.java:197) 09-03 18:09:04.821: e/androidruntime(28352): @ org.ksoap2.transport.serviceconnectionse.openoutputstream(serviceconnectionse.java:126) 09-03 18:09:04.821: e/androidruntime(28352): @ org.ksoap2.transport.httptransportse.call(httptransportse.java:179) 09-03 18:09:04.821: e/androidruntime(28352): @ org.ksoap2.transport.httptransportse.call(httptransportse.java:116) 09-03 18:09:04.821: e/androidruntime(28352): @ org.ksoap2.transport.httptransportse.call(httptransportse.java:111) 09-03 18:09:04.821: e/androidruntime(28352): @ com.example.provasoap.mainactivity.oncreate(mainactivity.java:47) 09-03 18:09:04.821: e/androidruntime(28352): @ android.app.activity.performcreate(activity.java:5133) 09-03 18:09:04.821: e/androidruntime(28352): @ android.app.instrumentation.callactivityoncreate(instrumentation.java:1087) 09-03 18:09:04.821: e/androidruntime(28352): @ android.app.activitythread.performlaunchactivity(activitythread.java:2175) 09-03 18:09:04.821: e/androidruntime(28352): ... 11 more
try it..
try using below code inside mainactivityactivity below setcontentview()
avoid networkonmainthread exception..
if (android.os.build.version.sdk_int > 9) { strictmode.threadpolicy policy = new strictmode.threadpolicy.builder().permitall().build(); strictmode.setthreadpolicy(policy); }
but, doing heavy operation inside background thread using asynctask without blocking main thread great!
and refer link...
Comments
Post a Comment