Reputation: 21
I'm using java to create web service, I have link
http://localhost:8181/NetBeansProjects/WsTlu30LichPhongVan?WSDL
On android studio I Use EasyWSDL Generator plugin to call WS by link and that generate HFIWsDangNhapPortBinding.java, then I 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 I call testLogin that just catch ?
Upvotes: 1
Views: 1803
Reputation: 2184
use below code to call soap web service from android app. it need ksoap library so download and add ksoap library to your 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){
for (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;
}
}
Upvotes: 1