我在本地IIS上发布了一个WebService,在浏览器可以正常访问但在安卓中不知如何调用。
以下是我的安卓代码,导入KSOAP3,建了一个KsoapHelper类
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 {
result = null;
result = (SoapObject)sSEnvelope.getResponse();
SoapObject childs = (SoapObject)result.getProperty(1);
return (SoapObject)childs.getProperty(0);
}
}
}
private String WEBSERVICE_URL = "http://10.0.2.2:8081/WebService1.asmx?wsdl";
private String NAMESPACE = "localhost";
public String loginSQL( String name, String pass) throws IOException, XmlPullParserException {
String result;
KsoapHelper.initKsoapHelper(WEBSERVICE_URL, NAMESPACE);
SoapObject request = KsoapHelper.GetSoapObject("Login");
// 设置需调用WebService接口需要传入的两个参数mobileCode、userId
request.addProperty("name", name);
request.addProperty("name", pass);
result=(String) KsoapHelper.GetResult(request, false);
return result;
}
调用无法返回result的值,有大神可以帮忙看看是哪里出问题了吗?