使用 kSOAP2 在 Android 中出现错误
Getting error in Android using kSOAP2
我得到的错误是这个
org.ksoap2.SoapFault 无法转换为 org.ksoap2.serialization.SoapObject
public final static String URL = "http://23.253.164.20:8096/login.asmx";
public static final String NAMESPACE = "http://23.253.164.20:8096";
public static final String SOAP_ACTION_PREFIX = "http://23.253.164.20:8096/getName";
private static final String METHOD = "getName";
private class AsyncTaskRunner extends AsyncTask<String, String, String> {
private String resp;
@Override
protected String doInBackground(String... params) {
publishProgress("Loading contents..."); // Calls onProgressUpdate()
try {
// SoapEnvelop.VER11 is SOAP Version 1.1 constant
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(
SoapEnvelope.VER11);
SoapObject request = new SoapObject(NAMESPACE, METHOD);
//bodyOut is the body object to be sent out with this envelope
envelope.bodyOut = request;
HttpTransportSE transport = new HttpTransportSE(URL);
try {
transport.call(NAMESPACE + SOAP_ACTION_PREFIX + METHOD, envelope);
} catch (IOException e) {
e.printStackTrace();
} catch (XmlPullParserException e) {
e.printStackTrace();
}
//bodyIn is the body object received with this envelope
if (envelope.bodyIn != null) {
//getProperty() Returns a specific property at a certain index.
SoapPrimitive resultSOAP = (SoapPrimitive) ((SoapObject) envelope.bodyIn)
.getProperty(0);
resp=resultSOAP.toString();
}
} catch (Exception e) {
e.printStackTrace();
resp = e.getMessage();
}
return resp;
}
/**
*
* @see android.os.AsyncTask#onPostExecute(java.lang.Object)
*/
@Override
protected void onPostExecute(String result) {
// execution of result of Long time consuming operation
// In this example it is the return value from the web service
textView.setText(result);
}
已检查可能性
1) Internet permission given
2) Ksoap2 library imported
3) server side method is running (you can the URL)
4) Not running on the emulator instead on the mobile phone
你在整个代码中有一些错误。
- 没有方法 "getName" - 看起来你的意思是 "getGreetingForName" 但我不确定,因为你没有提供参数 "stringName",
- 名称空间 = "http://23.253.164.20:8096/"; - 在末尾添加斜杠,
- transport.call(名称空间 + SOAP_ACTION_PREFIX + 方法,信封);
- 这是不正确的 - 因为这里调用的方法是“http://23.253.164.20:8096http://23.253.164.20:8096/getNamegetName”
另请参阅我对您的第二个帖子的回答 - 有有效的登录代码:
此致,
马辛
我得到的错误是这个
org.ksoap2.SoapFault 无法转换为 org.ksoap2.serialization.SoapObject
public final static String URL = "http://23.253.164.20:8096/login.asmx";
public static final String NAMESPACE = "http://23.253.164.20:8096";
public static final String SOAP_ACTION_PREFIX = "http://23.253.164.20:8096/getName";
private static final String METHOD = "getName";
private class AsyncTaskRunner extends AsyncTask<String, String, String> {
private String resp;
@Override
protected String doInBackground(String... params) {
publishProgress("Loading contents..."); // Calls onProgressUpdate()
try {
// SoapEnvelop.VER11 is SOAP Version 1.1 constant
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(
SoapEnvelope.VER11);
SoapObject request = new SoapObject(NAMESPACE, METHOD);
//bodyOut is the body object to be sent out with this envelope
envelope.bodyOut = request;
HttpTransportSE transport = new HttpTransportSE(URL);
try {
transport.call(NAMESPACE + SOAP_ACTION_PREFIX + METHOD, envelope);
} catch (IOException e) {
e.printStackTrace();
} catch (XmlPullParserException e) {
e.printStackTrace();
}
//bodyIn is the body object received with this envelope
if (envelope.bodyIn != null) {
//getProperty() Returns a specific property at a certain index.
SoapPrimitive resultSOAP = (SoapPrimitive) ((SoapObject) envelope.bodyIn)
.getProperty(0);
resp=resultSOAP.toString();
}
} catch (Exception e) {
e.printStackTrace();
resp = e.getMessage();
}
return resp;
}
/**
*
* @see android.os.AsyncTask#onPostExecute(java.lang.Object)
*/
@Override
protected void onPostExecute(String result) {
// execution of result of Long time consuming operation
// In this example it is the return value from the web service
textView.setText(result);
}
已检查可能性
1) Internet permission given
2) Ksoap2 library imported
3) server side method is running (you can the URL)
4) Not running on the emulator instead on the mobile phone
你在整个代码中有一些错误。
- 没有方法 "getName" - 看起来你的意思是 "getGreetingForName" 但我不确定,因为你没有提供参数 "stringName",
- 名称空间 = "http://23.253.164.20:8096/"; - 在末尾添加斜杠,
- transport.call(名称空间 + SOAP_ACTION_PREFIX + 方法,信封);
- 这是不正确的 - 因为这里调用的方法是“http://23.253.164.20:8096http://23.253.164.20:8096/getNamegetName”
另请参阅我对您的第二个帖子的回答 - 有有效的登录代码:
此致, 马辛