Call soap wsdl web service android -
i'm using java create web service, have link
http://localhost:8181/netbeansprojects/wstlu30lichphongvan?wsdl
on android studio use easywsdl generator plugin call ws link , generate hfiwsdangnhapportbinding.java, have code :
public string testlogin(string username, string pass) { string result = ""; try { result = wsdangnhapportbinding.testlogin(username, pass); } catch (exception e) { result = "catch"; e.getstacktrace(); } return result; }
when call testlogin catch ?
use below code call soap web service android app. need ksoap library download , add ksoap library android project
public class webservices { private static string serviceresponse; final static string namespace = "http://tempuri.org/"; final static string url = "http://" + appconstants.ip + "/mobileservice.asmx "; public static string dynamicwebcall(string methodname,hashmap<string,string> parameters) { string soap_action = "http://tempuri.org/"+methodname; try { soapobject request = new soapobject(namespace, methodname); if(parameters != null){ (map.entry<string, string> para : parameters.entryset()) { request.addproperty(para.getkey(), para.getvalue()); } } soapserializationenvelope envelope = new soapserializationenvelope( soapenvelope.ver11); new marshalbase64().register(envelope); // serialization envelope.dotnet = true; log.d("test", "url = " + url); log.d("test", "request= " + request.tostring()); envelope.setoutputsoapobject(request); httptransportse androidhttptransport = new httptransportse(url); androidhttptransport.call(soap_action, envelope); soapprimitive response = (soapprimitive) envelope.getresponse(); if (response != null) { serviceresponse = response.tostring(); } else { serviceresponse = "0"; } log.d("test", methodname + "response = " + serviceresponse); } catch (exception e) { log.d("test", "error - " + e.tostring()); serviceresponse = "error"; } return serviceresponse; } }
Comments
Post a Comment