http - How to call web service to achieve login system in Android? -
i have xml project. login sample code
http://10.99.99.99:8087/item/services/itemservice <soapenv:header/> <soapenv:body> <ser:userlogin> <!--optional:--> <arg0>admin</arg0> <!--optional:--> <arg1>admin</arg1> </ser:userlogin> </soapenv:body> </soapenv:envelope>
if succeed
<soap:body> <ns2:userloginresponse xmlns:ns2="http://services.ws.item/"> <return> <result>1</result> <msg>login succeed</msg> </return> </ns2:userloginresponse> </soap:body> </soap:envelope>
if not succeed
<soap:body> <ns2:userloginresponse xmlns:ns2="http://services.ws.item/"> <return> <result>-1</result> <msg>login failed</msg> </return> </ns2:userloginresponse> </soap:body> </soap:envelope>
the service connect mysql server.
i change test code, still cannot run, , sure wsdl work. logcat shows lot of error.
public class checkloginactivity extends activity { private static final string soap_action = "http://services.ws.item/userlogin"; private static final string method_name = "userlogin"; private static final string namespace = "http://services.ws.item/"; private static final string url = "http://10.99.99.99:8087/item/services/itemservice?wsdl"; private textview tv; private string response; @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.main); tv= (textview)findviewbyid(r.id.tv1); myasynctask myrequest = new myasynctask(); myrequest.execute(); } private class myasynctask extends asynctask<void, void, void> { @override protected void onpostexecute(void result) { super.onpostexecute(result); // tv.settext(response); } @override protected void onpreexecute() { super.onpreexecute(); } @override protected void doinbackground(void... arg0) { soapobject request = new soapobject(namespace, method_name); request.addproperty("arg0", "admin"); request.addproperty("arg1", "admin"); soapserializationenvelope envelope = new soapserializationenvelope(soapenvelope.ver11); envelope.setoutputsoapobject(request); httptransportse httptransport = new httptransportse(url); httptransport.debug = true; try { httptransport.call(soap_action, envelope); } catch (httpresponseexception e) { // todo auto-generated catch block e.printstacktrace(); } catch (ioexception e) { // todo auto-generated catch block e.printstacktrace(); } catch (xmlpullparserexception e) { // todo auto-generated catch block e.printstacktrace(); } //send request soapprimitive result; try { result = (soapprimitive) envelope.getresponse(); log.d("app",""+result.tostring()); response = result.tostring(); } catch (soapfault e) { // todo auto-generated catch block e.printstacktrace(); } return null; } } }
Comments
Post a Comment