Android: How to use ksoap2-android? -
i'm using webservice w3school testing, , have method:
public static float getcelsius(int fahrenheit) { string soap_action = "http://www.w3schools.com/xml/fahrenheittocelsius"; string method_name = "fahrenheittocelsius"; string namespace = "http://www.w3schools.com/xml/"; string url = "http://www.w3schools.com/xml/tempconvert.asmx"; soapobject request = new soapobject(namespace, method_name); request.addproperty("fahrenheit", fahrenheit); soapserializationenvelope envelope = new soapserializationenvelope(soapenvelope.ver11); envelope.dotnet = true; envelope.setoutputsoapobject(request); try { httptransportse transport = new httptransportse(url); transport.call(soap_action, envelope); soapprimitive result = (soapprimitive)envelope.getresponse(); return float.parsefloat(result.tostring()); } catch(exception e) { return 0; } }
but doesn't works, returns 0. set internet permission in androidmanifest.xml
this:
<uses-permission android:name="android.permission.internet" />
i'm using avd emulator, tried running app in tablet: didn't work.
any help? sorry bad english, hope understand.
here's solution:
you can't run code on main thread, have create thread this:
thread thread = new thread() { @override public void run() { string soap_action = "http://www.w3schools.com/xml/fahrenheittocelsius"; string method_name = "fahrenheittocelsius"; string namespace = "http://www.w3schools.com/xml/"; string url = "http://www.w3schools.com/xml/tempconvert.asmx"; soapobject request = new soapobject(namespace, method_name); request.addproperty("fahrenheit", "10"); soapserializationenvelope envelope = new soapserializationenvelope(soapenvelope.ver11); envelope.dotnet = true; envelope.setoutputsoapobject(request); try { httptransportse transport = new httptransportse(url); transport.call(soap_action, envelope); soapprimitive result = (soapprimitive) envelope.getresponse(); } catch (exception e) { log.e("tests", "ksoap2", e); } } }; thread.start();
anyway, answers.
Comments
Post a Comment