添加ksoap2-android-assembly-3.6.3-jar-with-dependencies.jar包
创建KsoapHelper类
package Model;
import org.ksoap2.serialization.SoapObject;
import org.ksoap2.serialization.SoapSerializationEnvelope;
import org.ksoap2.transport.HttpTransportSE;
import org.xmlpull.v1.XmlPullParserException;
import java.io.IOException;
import java.util.ArrayList;
public class KsoapHelper {
public static int timeOut = 30000;
public static String webServiceUrl;
public static String nameSpace;
public static int soapVersion = 120;
private KsoapHelper() {
}
public static void initKsoapHelper(String _webServiceUrl, String _nameSpace) {
initKsoapHelper(timeOut, _webServiceUrl, _nameSpace, soapVersion);
}
public static void initKsoapHelper(String _webServiceUrl, String _nameSpace, int _version) {
initKsoapHelper(timeOut, _webServiceUrl, _nameSpace, _version);
}
public static void initKsoapHelper(int _timeOut, String _webServiceUrl, String _nameSpace, int _version) {
nameSpace = _nameSpace;
webServiceUrl = _webServiceUrl;
timeOut = _timeOut;
soapVersion = _version;
}
public static SoapObject GetSoapObject(String methodName) {
SoapObject object = new SoapObject(nameSpace, methodName);
return object;
}
public static SoapObject GetSoapObject(String nameSpace, String methodName) {
SoapObject object = new SoapObject(nameSpace, methodName);
return object;
}
public static Object GetResult(SoapObject object, boolean isSimple) throws IOException, XmlPullParserException {
SoapSerializationEnvelope sSEnvelope = new SoapSerializationEnvelope(120);
sSEnvelope.bodyOut = object;
sSEnvelope.dotNet = true;
HttpTransportSE httpTransSE = new HttpTransportSE(webServiceUrl, timeOut);
httpTransSE.debug = true;
httpTransSE.call((String)null, sSEnvelope);
SoapObject result;
if (isSimple) {
result = null;
Object simpleResult = sSEnvelope.getResponse();
return simpleResult.toString();
} else {
ArrayList <String>temp = new ArrayList<>();
result = (SoapObject)sSEnvelope.bodyIn;
SoapObject childs = (SoapObject)result.getProperty(0);
for(int i=0;i<childs.getPropertyCount();i++)
{
temp.add(childs.getProperty(i).toString());
}
return temp;
}
}
}