答案 0 :(得分:0)
是的,您可以通过为每个调用指定方法名称来调用所有方法。 例如:
public static String connect(String methodName, String[] args,String[] values) {
try {
SoapObject request = new SoapObject(YOUR_NAMESPACE, methodName);
int i = 0;
for (String s : args) {
PropertyInfo propInfo = new PropertyInfo();
propInfo.name = s;
propInfo.type = PropertyInfo.STRING_CLASS;
request.addProperty(propInfo, values[i]);
i++;
}
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(
SoapEnvelope.VER11);
envelope.setOutputSoapObject(request);
HttpTransportSE androidHttpTransport = new HttpTransportSE(
YOUR_URL);
androidHttpTransport.call(YOUR_NAMESPACE + methodName, envelope);
SoapPrimitive resultsRequestSOAP = (SoapPrimitive) envelope
.getResponse(); // Receiving return string
String result = resultsRequestSOAP.toString();
if (result != null) {
return result;
}
return "";
} catch (Exception ex) {
ex.printStackTrace();
Log.d("Web Service Exception", ex.toString());
return "";
}
}
并使用辅助方法,如
public static String Get_ID(parameter) {
String[] args = new String[1];
String[] values = new String[1];
args[0] = "parameter";
values[0] = parameter;
String result = connect("Get_ID", args, values);
return result;
}
如果您有多个方法,则使用特定参数和方法名称重复辅助方法。然后可以调用此辅助方法来获取活动中的数据。